Documentation
¶
Index ¶
- Variables
- func Any[T any](in []T, f func(T) bool) bool
- func AtIdx[T any](s []T, index int) T
- func BytesToSize(bytes float64) string
- func Clamp(val, minV, maxV int) int
- func Count[T any](array []T, f func(T) bool) int
- func Defer(f func() error, log zerolog.Logger, wg *sync.WaitGroup)
- func Ext(uri string, defaultExt ...string) string
- func Filter[T any](in []T, f func(T) bool) []T
- func Find[T any](in []T, f func(T) bool) *T
- func FindOk[T any](in []T, f func(T) bool) (T, bool)
- func FlatMap[E any](in [][]E) []E
- func FlatMapMany[E any](in ...[]E) []E
- func ForEach[T any](s []T, f func(T))
- func GenerateApiKey() (string, error)
- func GenerateSecret(length int) (string, error)
- func GroupBy[K comparable, V any](s []V, f func(V) K) map[K][]V
- func HumanReadableSpeed(s int64) string
- func Identity[T any](t T) func() T
- func IsSameDay(t1, t2 time.Time) bool
- func Keys[K comparable, V any](m map[K]V) []K
- func Map[T, S any](in []T, f func(T) S) []S
- func MapKeys[K comparable, V, T any](m map[K]V, f func(K) T) []T
- func MapToString[T ~string](m []T) []string
- func MapValues[K comparable, V, T any](m map[K]V, f func(V) T) []T
- func MapWithIdx[T, S any](in []T, f func(int, T) S) []S
- func MapWithState[T, U any, S any](in []T, state S, f func(T, S) (U, S)) []U
- func MaybeMap[T, S any](in []T, f func(T) (S, bool)) []S
- func Must(err error)
- func MustHave[T any](result T, ok bool) T
- func MustInvoke[T any](c Invoker) T
- func MustReturn[T any](result T, err error) T
- func NewRedisCacheStorage(log zerolog.Logger, clientName, redisAddr string) fiber.Storage
- func NonEmpty(s ...string) string
- func Normalize(s string) string
- func OrDefault[T any](array []T, defaultValue T) T
- func OrElse(s string, def string) string
- func PadFloatFromString(s string, n int) string
- func PadInt(i int, n int) string
- func Percent(a, b int64) int64
- func SafeFloat(s string) float64
- func Shorten(s string, length int) string
- func SortFloats(a, b string) int
- func Stringify(i int) string
- func Ternary[T any](condition bool, ifTrue, ifFalse T) T
- func TrimLeadingZero(s string) string
- func Values[K comparable, V any](m map[K]V) []V
- func Wait(wg *sync.WaitGroup) <-chan struct{}
- func WaitFor(wg *sync.WaitGroup, d time.Duration)
- type CachedItem
- type Invoker
- type Option
- type SafeMap
- type Settable
- type Toggles
Constants ¶
This section is empty.
Variables ¶
var (
ErrCachedItemExpired = errors.New("cached item has expired")
)
Functions ¶
func AtIdx ¶
AtIdx returns the value at the given index, unless out of range; then return the zero value for the element
func BytesToSize ¶
func FlatMapMany ¶
func FlatMapMany[E any](in ...[]E) []E
func GenerateApiKey ¶
func GenerateSecret ¶
func GroupBy ¶
func GroupBy[K comparable, V any](s []V, f func(V) K) map[K][]V
func HumanReadableSpeed ¶
func Keys ¶
func Keys[K comparable, V any](m map[K]V) []K
func MapKeys ¶
func MapKeys[K comparable, V, T any](m map[K]V, f func(K) T) []T
func MapToString ¶
func MapValues ¶
func MapValues[K comparable, V, T any](m map[K]V, f func(V) T) []T
func MapWithIdx ¶
func MapWithState ¶
func MustInvoke ¶
MustInvoke tries construction T with the given Container Ensure the needed method has been Provider to the Container
func MustReturn ¶
func NewRedisCacheStorage ¶
func PadFloatFromString ¶
PadFloatFromString returns the float as a string, with pad called on the whole part and the decimal part copied from the input string, if present This method assumes the string is a valid float
func Percent ¶
Percent returns the % of a contained in b. At most 100 is returned. Percent(a, 0) = 100 for a != 0, Percent(0,0) = 0
func SortFloats ¶
func TrimLeadingZero ¶
func Values ¶
func Values[K comparable, V any](m map[K]V) []V
Types ¶
type CachedItem ¶
CachedItem is the simplest way of caching an item, do not use for more complicated stuff does not evict anything itself
func NewCachedItem ¶
func NewCachedItem[T any](data T, exp time.Duration) CachedItem[T]
type Invoker ¶
type Invoker interface {
Invoke(function interface{}, opts ...dig.InvokeOption) (err error)
}
type SafeMap ¶
type SafeMap[K comparable, V any] interface { Has(k K) bool Get(k K) (V, bool) Set(k K, v V) Len() int Delete(k K) Clear() Keys() []K Values() []V // ForEach iterates over the map, and unlocks during function call ForEach(f func(k K, v V)) // ForEachSafe iterates over the map, does not unlock during function all. // // Use SafeMap.ForEach if you need to modify the map ForEachSafe(f func(k K, v V)) Any(f func(k K, v V) bool) bool Count(f func(k K, v V) bool) int Find(f func(k K, v V) bool) (*V, bool) }
func NewSafeMap ¶
func NewSafeMap[K comparable, V any](m ...map[K]V) SafeMap[K, V]
type Settable ¶
type Settable[T any] struct { // contains filtered or unexported fields }
Settable represents a variable where the zero value has more meaning than undecided yet A Settable may be Set more than once
type Toggles ¶
type Toggles[K comparable] struct { // contains filtered or unexported fields }
func NewToggles ¶
func NewToggles[K comparable]() *Toggles[K]