Documentation ¶
Index ¶
- func Cast[T any](val any) T
- func CastBSON[T any](val any) T
- func CastBSONSlice[T any](slice []interface{}) []T
- func CastJSON[T any](val any) T
- func CastSlice[T any](slice []any) []T
- func Coalesce[T comparable](vv ...T) T
- func CreateAndWriteToFile(path string, content string)
- func DefaultCTX(slice []context.Context) context.Context
- func DefaultQuery(query ...primitive.M) primitive.M
- func EQ(a, b interface{}) bool
- func ElementAtIndex[T any](slice []T, index int) T
- func First[T any](slice []T) T
- func FirstPtr[T any](slice []T) *T
- func FromBSON[T any](bytes []byte) T
- func FromJSON[T any](bytes []byte) T
- func GT(a, b interface{}) bool
- func GTE(a, b interface{}) bool
- func IsEmpty(value interface{}) bool
- func LT(a, b interface{}) bool
- func LTE(a, b interface{}) bool
- func Must(err error)
- func Protect(f func())
- func ProtectWithCallback(f func(), onError func(err interface{}))
- func SetDefaults(ptr interface{}) error
- func ToBSON(val any) []byte
- func ToBSONDoc(v interface{}) (doc *bson.M)
- func ToJSON(val any) []byte
- func ToMap(s any) map[string]interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cast ¶
Converts any type to a given type. If conversion fails, it returns the zero value of the given type.
func CastBSON ¶
Converts any type to a given type based on their bson representation. It partially fills the target in case they are not directly compatible.
func CastBSONSlice ¶
func CastBSONSlice[T any](slice []interface{}) []T
func CastJSON ¶
Converts any type to a given type based on their json representation. It partially fills the target in case they are not directly compatible.
func Coalesce ¶
func Coalesce[T comparable](vv ...T) T
Coalesce returns its left-most value if it's not zero value
func CreateAndWriteToFile ¶
func DefaultCTX ¶
Extracts and returns the context from an optional slice of contexts. If the slice is empty, it returns a new context.
func DefaultQuery ¶
Extracts and returns the query from an optional slice of queries. If the slice is empty, it returns an empty query.
func ElementAtIndex ¶
func Protect ¶
func Protect(f func())
Utility function that recovers from a panic and logs the error and stack trace.
func ProtectWithCallback ¶
func ProtectWithCallback(f func(), onError func(err interface{}))
Utility function that recovers from a panic and calls a given callback function with the error.
func SetDefaults ¶
func SetDefaults(ptr interface{}) error
Types ¶
This section is empty.