Documentation
¶
Index ¶
- func All[Fn ~func() bool](funcs ...Fn) bool
- func Any(funcs ...func() bool) bool
- func Copy[T any](src, dst *T)
- func GenerateUUID(ps ...string) string
- func GetMimeTypeByFileName(filename string) string
- func IsDir(path string) error
- func IsImageFileExt(ext string) bool
- func IsNil(v any) bool
- func IsTimeoutError(err error) bool
- func Last[T any, Slice ~[]T](slice Slice) T
- func Must[T any](val T, err error) T
- func NotifyOnEnd(ch chan<- struct{}, fn ...func())
- func Ptr[T any](val T) *T
- func RandomChoice[T any, Slice ~[]T](slice Slice) T
- func Retry(fn func() error, times int) (err error)
- func Reverse[T any](obj []T) []T
- type RWNopeCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All returns true if all provided functions return true. Optimization: Short-circuits on first false result.
func Any ¶
Any returns true if any provided function returns true. Optimization: Short-circuits on first true result.
func Copy ¶
func Copy[T any](src, dst *T)
Copy copies the value from src to dst using unsafe pointer operations for zero-overhead copying. Optimization: Uses unsafe to avoid allocation and deep copying.
func GenerateUUID ¶
GenerateUUID generates a UUID with optional prefix and suffix. Optimization: Efficient string concatenation with minimal allocations.
func GetMimeTypeByFileName ¶
GetMimeTypeByFileName returns the MIME type based on the file extension. Optimization: Uses standard library mime.TypeByExtension for efficiency.
func IsDir ¶
IsDir checks if the path is a directory, returning an error if not. Optimization: Uses os.Stat directly for minimal overhead.
func IsImageFileExt ¶
IsImageFileExt checks if the extension matches a known image file extension. Optimization: Uses a fixed array and linear search (sufficient for small set).
func IsNil ¶
IsNil checks if the value is nil or a nil pointer using reflection. Optimization: Combines direct nil check with reflection-based pointer check.
func IsTimeoutError ¶
IsTimeoutError checks if the error indicates a timeout from various sources. Optimization: Uses errors.Is and os.IsTimeout for efficient error checking.
func Last ¶
func Last[T any, Slice ~[]T](slice Slice) T
Last returns the last element of a slice. Optimization: Direct index access for O(1) performance.
func Must ¶
Must returns the value and discards the error, useful for simplifying code when errors are ignorable. Optimization: No additional overhead beyond returning the value.
func NotifyOnEnd ¶
func NotifyOnEnd(ch chan<- struct{}, fn ...func())
NotifyOnEnd runs each function in a goroutine and sends a signal on the channel when each completes. Optimization: Launches goroutines concurrently for parallelism.
func Ptr ¶
func Ptr[T any](val T) *T
Ptr returns a pointer to the provided value. Optimization: Simple allocation, no additional overhead possible.
func RandomChoice ¶
func RandomChoice[T any, Slice ~[]T](slice Slice) T
RandomChoice selects a random element from the slice using a seeded random source. Optimization: Pre-seeded random source avoids repeated initialization.
Types ¶
type RWNopeCloser ¶
RWNopeCloser is an interface combining Reader, Writer, and Closer.
func NopeCloserRW ¶
func NopeCloserRW(rw io.ReadWriter) RWNopeCloser
NopeCloserRW wraps an io.ReadWriter with a no-op Closer. Optimization: Simple wrapping with no additional overhead.