e_utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cast

func Cast[T any](val any) T

Converts any type to a given type. If conversion fails, it returns the zero value of the given type.

func CastBSON

func CastBSON[T any](val any) T

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

func CastJSON[T any](val any) T

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 CastSlice

func CastSlice[T any](slice []any) []T

func Coalesce

func Coalesce[T comparable](vv ...T) T

Coalesce returns its left-most value if it's not zero value

func CreateAndWriteToFile

func CreateAndWriteToFile(path string, content string)

func DefaultCTX

func DefaultCTX(slice []context.Context) context.Context

Extracts and returns the context from an optional slice of contexts. If the slice is empty, it returns a new context.

func DefaultQuery

func DefaultQuery(query ...primitive.M) primitive.M

Extracts and returns the query from an optional slice of queries. If the slice is empty, it returns an empty query.

func EQ added in v0.0.6

func EQ(a, b interface{}) bool

func ElementAtIndex

func ElementAtIndex[T any](slice []T, index int) T

func First

func First[T any](slice []T) T

func FirstPtr

func FirstPtr[T any](slice []T) *T

func FromBSON

func FromBSON[T any](bytes []byte) T

Converts a byte array to a given type.

func FromJSON

func FromJSON[T any](bytes []byte) T

Converts a byte array to a given type.

func GT added in v0.0.6

func GT(a, b interface{}) bool

func GTE added in v0.0.6

func GTE(a, b interface{}) bool

func IsEmpty

func IsEmpty(value interface{}) bool

func LT added in v0.0.6

func LT(a, b interface{}) bool

func LTE added in v0.0.6

func LTE(a, b interface{}) bool

func Must

func Must(err error)

Panics if err is not nil.

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

func ToBSON

func ToBSON(val any) []byte

Converts a given value to a byte array.

func ToBSONDoc

func ToBSONDoc(v interface{}) (doc *bson.M)

Converts an interface to a bson document

func ToJSON

func ToJSON(val any) []byte

Converts a given value to a byte array.

func ToMap

func ToMap(s any) map[string]interface{}

Converts any type to a map[string]interface{}.

Types

This section is empty.

Jump to

Keyboard shortcuts

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