Documentation ¶
Index ¶
- Constants
- Variables
- func BoolPtr(v bool) *bool
- func CamelToSnakeCase(camelCase string) string
- func ConvertSlice(slice []interface{}) interface{}
- func Float64Ptr(v float64) *float64
- func FromPtr[T primitives](t *T) T
- func IntPtr(v int) *int
- func MustSetIfNotNil(dst interface{}, src interface{})
- func MustSetIfNotZero(dst interface{}, src interface{})
- func ParseDuration(v string) time.Duration
- func ParseString(s string) interface{}
- func ParseTime(layout, v string) time.Time
- func ParseTimeISO8601(v string) time.Time
- func RandomInt64N(n int64) int64
- func RandomIntN(n int) int
- func RandomString(length int) string
- func RandomStringWithCharset(length int, charset RandomCharset) string
- func RecoverableFunc[T SupportedRecoverableFunc](panicingFunc T) func() error
- func Remove[T any](slice []T, index int) []T
- func RemoveStable[T any](slice []T, index int) []T
- func Reverse[T any](input []T)
- func SetIfNotNil(dst interface{}, src interface{}) (err error)
- func SetIfNotZero(dst interface{}, src interface{}) (err error)
- func StringPtr(v string) *string
- func ToPtr[T any](t T) *T
- func UIntPtr(v uint) *uint
- func UnQuote(s string) string
- func UuidPtr(v uuid.UUID) *uuid.UUID
- type CommaSeparatedSlice
- type ContextValuer
- type Duration
- type GenericSet
- func (s GenericSet[T]) Add(values ...T) GenericSet[T]
- func (s GenericSet[T]) Copy() GenericSet[T]
- func (s GenericSet[T]) Equals(another GenericSet[T]) bool
- func (s GenericSet[T]) Has(value T) bool
- func (s GenericSet[T]) HasAll(values ...T) bool
- func (s GenericSet[T]) MarshalJSON() ([]byte, error)
- func (s GenericSet[T]) Remove(values ...T) GenericSet[T]
- func (s *GenericSet[T]) UnmarshalJSON(data []byte) error
- func (s GenericSet[T]) Values() []T
- type ListableContext
- type MutableContext
- type MutableContextAccessor
- type RandomCharset
- type Set
- func (s Set) Add(values ...interface{}) Set
- func (s Set) Copy() Set
- func (s Set) Equals(another Set) bool
- func (s Set) Has(value interface{}) bool
- func (s Set) HasAll(values ...interface{}) bool
- func (s Set) MarshalJSON() ([]byte, error)
- func (s Set) Remove(values ...interface{}) Set
- func (s *Set) UnmarshalJSON(data []byte) error
- func (s Set) Values() []interface{}
- type StringSet
- func (s StringSet) Add(values ...string) StringSet
- func (s StringSet) Copy() StringSet
- func (s StringSet) Equals(another StringSet) bool
- func (s StringSet) Has(value string) bool
- func (s StringSet) HasAll(values ...string) bool
- func (s StringSet) MarshalJSON() ([]byte, error)
- func (s StringSet) Remove(values ...string) StringSet
- func (s StringSet) ToSet() Set
- func (s *StringSet) UnmarshalJSON(data []byte) error
- func (s StringSet) Values() []string
- type SupportedRecoverableFunc
Constants ¶
const ( ISO8601Seconds = "2006-01-02T15:04:05Z07:00" //time.RFC3339 ISO8601Milliseconds = "2006-01-02T15:04:05.000Z07:00" )
Variables ¶
var ( TRUE = true FALSE = false )
var (
MaxTime = time.Unix(1<<63-1, 0).UTC()
)
Functions ¶
func CamelToSnakeCase ¶
CamelToSnakeCase convert "camelCase" string to "snake-case"
func ConvertSlice ¶
func ConvertSlice(slice []interface{}) interface{}
ConvertSlice attempt to convert []interface{} to []elementType using the first element's type. if given slice is empty, or any elements is not the same type of first one, same slice is returned
func Float64Ptr ¶
Float64Ptr Deprecated: make use of ToPtr instead
func FromPtr ¶
func FromPtr[T primitives](t *T) T
FromPtr will take a pointer type and return its value if it is not nil. Otherwise, it will return the default value for that type. ex,
var s *string FromPtr(s) // results in "" *s = "hello" FromPtr(s) // results in "hello" var b *bool FromPtr(b) // results in false ... // Custom Types with underlying types of primitives type String string var s *String FromPtr(s) // results in "" - but typed String *s = String("hello") FromPtr(s) // results in "hello" - but typed String
func MustSetIfNotNil ¶
func MustSetIfNotNil(dst interface{}, src interface{})
MustSetIfNotNil takes "src" pointer (e.g. *bool) and set its dereference value to "dst" if not nil this function panic if: - "dst" and "src" are not pointer - "src" is not convertable to "dst" - "dst" not point to a settable value
func MustSetIfNotZero ¶
func MustSetIfNotZero(dst interface{}, src interface{})
MustSetIfNotZero takes "src" value (e.g. bool) and set its value to "dst" if not zero this function panic if: - "dst" is not pointer or not point to a settable value - "src" is not convertable to "dst"
func ParseDuration ¶
func ParseString ¶
func ParseString(s string) interface{}
func ParseTimeISO8601 ¶
func RandomInt64N ¶
RandomInt64N returns, as an int64, a non-negative uniform number in the half-open interval [0,n). This function uses "crypto/rand" and fallback to "math/rand". It panics if n <= 0.
func RandomIntN ¶
RandomIntN returns, as an int64, a non-negative uniform number in the half-open interval [0,n). This function uses "crypto/rand" and fallback to "math/rand". It panics if n <= 0.
func RandomString ¶
RandomString returns a random Alphanumeric string of given "length" this function uses "crypto/rand" and fallback to "math/rand" It panics if len(charset) > 255, and returns empty string if length is non-positive
func RandomStringWithCharset ¶
func RandomStringWithCharset(length int, charset RandomCharset) string
RandomStringWithCharset returns a random string of given "length" containing only characters from given "charset" this function uses "crypto/rand" and fallback to "math/rand" It returns empty string if length is non-positive, and only the first 256 chars in "charset" are used
func RecoverableFunc ¶
func RecoverableFunc[T SupportedRecoverableFunc](panicingFunc T) func() error
RecoverableFunc wrap a panicing function with following signature - func() - func() error into a func() error, where the recovered value is converted to error This function panics if the given function has incorrect signature
func Remove ¶
Remove will not keep the ordering of the slice. It has a very fast operation. This function will automatically type itself using type inference
intSlice := []int{1, 2, 3, 4} intSlice = Remove(intSlice, 1) result: {1, 4, 3}
func RemoveStable ¶
RemoveStable will remove an element from the slice and keep its order. This operation can be potentially costly depending on how large the slice is since it needs to shift all elements that appear after index i over by 1.
This function will automatically type itself using type inference.
If the given index is not within the bounds of the slice, then the function will panic
func SetIfNotNil ¶
func SetIfNotNil(dst interface{}, src interface{}) (err error)
SetIfNotNil is equivalent of MustSetIfNotNil, this function returns error instead of panic
func SetIfNotZero ¶
func SetIfNotZero(dst interface{}, src interface{}) (err error)
SetIfNotZero is equivalent of MustSetIfNotZero, this function returns error instead of panic
Types ¶
type CommaSeparatedSlice ¶
type CommaSeparatedSlice []string
CommaSeparatedSlice alias of []string that can deserialize from comma delimited string
func (CommaSeparatedSlice) MarshalText ¶
func (s CommaSeparatedSlice) MarshalText() ([]byte, error)
MarshalText encoding.TextMarshaler
func (*CommaSeparatedSlice) UnmarshalJSON ¶
func (s *CommaSeparatedSlice) UnmarshalJSON(data []byte) error
UnmarshalJSON json.Unmarshaler
func (*CommaSeparatedSlice) UnmarshalText ¶
func (s *CommaSeparatedSlice) UnmarshalText(data []byte) error
UnmarshalText encoding.TextUnmarshaler
type ContextValuer ¶
type ContextValuer func(key interface{}) interface{}
ContextValuer is an additional source of context.Context.Value(any)) used by MutableContext to search values with key. When MutableContext cannot find given key in its internal store, it will go through all ContextValuers before pass along the key-value searching to its parent context. See NewMutableContext and MakeMutableContext
type Duration ¶
func (Duration) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Duration) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler
type GenericSet ¶
type GenericSet[T comparable] map[T]void
func NewGenericSet ¶
func NewGenericSet[T comparable](values ...T) GenericSet[T]
func (GenericSet[T]) Add ¶
func (s GenericSet[T]) Add(values ...T) GenericSet[T]
func (GenericSet[T]) Copy ¶
func (s GenericSet[T]) Copy() GenericSet[T]
func (GenericSet[T]) Equals ¶
func (s GenericSet[T]) Equals(another GenericSet[T]) bool
func (GenericSet[T]) Has ¶
func (s GenericSet[T]) Has(value T) bool
func (GenericSet[T]) HasAll ¶
func (s GenericSet[T]) HasAll(values ...T) bool
func (GenericSet[T]) MarshalJSON ¶
func (s GenericSet[T]) MarshalJSON() ([]byte, error)
MarshalJSON json.Marshaler
func (GenericSet[T]) Remove ¶
func (s GenericSet[T]) Remove(values ...T) GenericSet[T]
func (*GenericSet[T]) UnmarshalJSON ¶
func (s *GenericSet[T]) UnmarshalJSON(data []byte) error
UnmarshalJSON json.Unmarshaler
func (GenericSet[T]) Values ¶
func (s GenericSet[T]) Values() []T
type ListableContext ¶
ListableContext is supplementary interface of MutableContext, listing all values stored in the context
type MutableContext ¶
MutableContext wraps context.Context with an internal KV pairs storage. KV pairs stored in this context can be changed in later time. To change/list KV pairs on any context.Context that inherit from MutableContext, use FindMutableContext to obtain a MutableContextAccessor. See FindMutableContext and MutableContextAccessor for more details
func MakeMutableContext ¶
func MakeMutableContext(parent context.Context, valuers ...ContextValuer) MutableContext
MakeMutableContext return the context itself if it's already a MutableContext and no additional ContextValuer are specified. Otherwise, wrap the given context as MutableContext. Note: If the given context itself is not a MutableContext but its hierarchy contains MutableContext as parent context,
a new MutableContext is created and its mutable store (map) is not shared with the one from the hierarchy.
func NewMutableContext ¶
func NewMutableContext(parent context.Context, valuers ...ContextValuer) MutableContext
NewMutableContext Wrap given context.Context with a mutable store and optionally additional KV sources defined as ContextValuer
type MutableContextAccessor ¶
func FindMutableContext ¶
func FindMutableContext(ctx context.Context) MutableContextAccessor
FindMutableContext search for MutableContext from given context.Context's inheritance hierarchy, and return a MutableContextAccessor for key-values manipulation. If MutableContext is not found, nil is returned.
Important: This function may returns parent context of the given one. Therefore, changing values may affect parent context.
type RandomCharset ¶
type RandomCharset string
RandomCharset is a string containing all acceptable UTF-8 characters for random string generation
const ( CharsetAlphanumeric RandomCharset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" CharsetAlphabetic RandomCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" )
type Set ¶
type Set map[interface{}]void
func NewSetFrom ¶
func NewSetFrom(i interface{}) Set
func NewSetFromStringSet ¶
func (*Set) UnmarshalJSON ¶
UnmarshalJSON json.Unmarshaler
type StringSet ¶
type StringSet map[string]void
func NewStringSet ¶
func NewStringSetFrom ¶
func NewStringSetFrom(i interface{}) StringSet
func NewStringSetFromSet ¶
func (StringSet) MarshalJSON ¶
MarshalJSON json.Marshaler
func (*StringSet) UnmarshalJSON ¶
UnmarshalJSON json.Unmarshaler
type SupportedRecoverableFunc ¶
type SupportedRecoverableFunc interface { ~func() | ~func() error }
A SupportedRecoverableFunc is a function that can be converted by RecoverableFunc