Documentation
¶
Index ¶
- func AnyToBool(value any) bool
- func Contains[T comparable](list []T, target T) bool
- func ExpectedNumber[T Int](v any) T
- func IntToString[T Int](i T) string
- func JSONMarshal(data interface{}) ([]byte, error)
- func JSONUnmarshal(data []byte, v interface{}) error
- func MapToStruct[T any](value any) (item T, err error)
- func MapToStructOrDefault[T any](value any) T
- func OffsetByType[T Int](page, limit uint) T
- func PointerTypeToType[T any](input *T) T
- func Ptr[T any](v T) *T
- func PtrDateTimeString(dt *carbon.DateTime) *string
- func PtrFormat[T any](v *T, formatter func(T) string) *string
- func StringToInt[T Int](s string) T
- func TypeToPointerType[T any](input T) *T
- func Unique[T comparable](elements []T) (result []T)
- func ValueOrDefault[T comparable](value, defaultValue T) T
- type Int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶ added in v0.19.4
func Contains[T comparable](list []T, target T) bool
Contains checks if a target value exists in a given list.
func ExpectedNumber ¶ added in v0.19.4
func IntToString ¶ added in v0.19.4
IntToString converts an integer value to a string.
func JSONMarshal ¶ added in v0.19.4
func JSONUnmarshal ¶ added in v0.19.4
func MapToStruct ¶ added in v0.19.4
func MapToStructOrDefault ¶ added in v0.19.4
MapToStructOrDefault converts any value to T by marshalling to JSON then unmarshalling into T. Returns the zero value of T if conversion fails.
func OffsetByType ¶ added in v0.19.4
OffsetByType to get offset from page and limit, min value for page = 1
func PointerTypeToType ¶ added in v0.19.4
func PointerTypeToType[T any](input *T) T
PointerTypeToType converts a pointer value to its original type.
func PtrDateTimeString ¶ added in v0.19.4
PtrDateTimeString converts a *carbon.DateTime to a formatted *string. Returns nil if dt is nil or is a zero date (0001-01-01 00:00:00), preventing zero-dates stored in the database from leaking into API responses.
func PtrFormat ¶ added in v0.19.4
PtrFormat calls formatter on v if v is non-nil, returning a *string. Returns nil if v is nil. The caller controls all formatting logic.
func StringToInt ¶ added in v0.19.4
StringToInt converts a string to an integer value.
func TypeToPointerType ¶ added in v0.19.4
func TypeToPointerType[T any](input T) *T
TypeToPointerType converts a value to its pointer type.
func Unique ¶ added in v0.19.4
func Unique[T comparable](elements []T) (result []T)
Unique returns unique value in as slice
func ValueOrDefault ¶ added in v0.19.4
func ValueOrDefault[T comparable](value, defaultValue T) T
ValueOrDefault returns the provided value if it is not empty, otherwise returns the defaultValue.