util

package
v0.8.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 22 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContext       = errors.New("context")
	ErrChannelClosed = errors.New("channel closed")
)
View Source
var (
	ErrNotImplemented = errors.New("not implemented")
	ErrUnbelievable   = errors.New("unbelievable")
)
View Source
var (
	ErrUnmarshalByteArray = errors.New("unmarshal byte array error")
	ErrUnmarshalString    = errors.New("unmarshal string error")
	ErrUnmarshal          = errors.New("unmarshal error")
)

Functions

func ApplyIfNotNil added in v0.1.4

func ApplyIfNotNil[E any, R any](value *E, apply func(*E) *R) *R

func ApplyIfNotNilDefault added in v0.1.4

func ApplyIfNotNilDefault[E any, R any](value *E, defaultValue R, apply func(E) R) R

func CopyFile

func CopyFile(source string, dest string) error

func FileExists

func FileExists(filename string) (os.FileInfo, bool)

func FormatDuration

func FormatDuration(duration time.Duration) string

func Gunzip

func Gunzip(data []byte) ([]byte, error)

func Gzip

func Gzip(data []byte) ([]byte, error)

func Identity added in v0.5.14

func Identity[T any](in T) T

func IsNil

func IsNil(v any) bool

func Map

func Map[IN any, OUT any](slice []IN, mappingFunction func(x IN) (OUT, error)) ([]OUT, error)

func MapSimple

func MapSimple[IN any, OUT any](slice []IN, mappingFunction func(x IN) OUT) []OUT

func Mat3ToQuaternion

func Mat3ToQuaternion(m [3][3]float64) [4]float64

Mat3ToQuaternion converts a 3x3 rotation matrix to a quaternion. nolint:varnamelen

func MaxDuration

func MaxDuration(durations ...time.Duration) time.Duration

func MaxDurationSlice

func MaxDurationSlice(durations []time.Duration) time.Duration

func NewPoint

func NewPoint(lon float64, lat float64) orb.Point

func OrDefault

func OrDefault[T any](ref *T, defaultValue T) T

func QuaternionToMat3

func QuaternionToMat3(q [4]float64) [3][3]float64

QuaternionToMat3 converts a quaternion to a 3x3 rotation matrix. nolint:varnamelen

func ReadFromChannel added in v0.6.8

func ReadFromChannel[T any](ctx context.Context, ch <-chan T, defaultValue T) (T, error)

func ReadFromChannelWithTimeout added in v0.6.8

func ReadFromChannelWithTimeout[T any](ctx context.Context, ch <-chan T, timeout time.Duration, defaultValue T) (T, error)

func RemoveImageAlphaChannel

func RemoveImageAlphaChannel(img image.Image) image.Image

func ResizeImage

func ResizeImage(
	img image.Image,
	width int,
	height int,
	interpolationFunction resize.InterpolationFunction,
) (image.Image, error)

ResizeImage resizes an image to the specified dimensions using the provided interpolation function. nolint:unparam

func RoundFloat64ToInt64 added in v0.8.20

func RoundFloat64ToInt64(float float64) int64

func RoundFloat64ToPrecision

func RoundFloat64ToPrecision(f float64, precision int) float64

func Sha1

func Sha1(data []byte) (string, error)

Sha1 computes SHA1 hash of the data. nolint:unparam,gosec

func SliceSort

func SliceSort[T any](slice []T, comp func(T, T) bool)

func SliceSum

func SliceSum[T any, R any](slice []T, start R, reducer func(prev R, current T) R) R

func SliceUnique

func SliceUnique[T comparable](slice []T) []T

func Ternary added in v0.1.4

func Ternary[T any](whatIf bool, then T, other T) T

func TernaryFunc added in v0.1.4

func TernaryFunc[R any](whatIf bool, then func() R, other func() R) R

func UnmarshalJsonToId

func UnmarshalJsonToId[T any](
	data []byte,
	defaultValue T,
	fn func(uuidValue uuid.UUID) T,
) (T, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址