types

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToBool added in v0.19.4

func AnyToBool(value any) bool

AnyToBool converts any value to a boolean using the cast library.

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 ExpectedNumber[T Int](v any) T

func IntToString added in v0.19.4

func IntToString[T Int](i T) string

IntToString converts an integer value to a string.

func JSONMarshal added in v0.19.4

func JSONMarshal(data interface{}) ([]byte, error)

func JSONUnmarshal added in v0.19.4

func JSONUnmarshal(data []byte, v interface{}) error

func MapToStruct added in v0.19.4

func MapToStruct[T any](value any) (item T, err error)

func MapToStructOrDefault added in v0.19.4

func MapToStructOrDefault[T any](value any) T

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

func OffsetByType[T Int](page, limit uint) T

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 Ptr

func Ptr[T any](v T) *T

func PtrDateTimeString added in v0.19.4

func PtrDateTimeString(dt *carbon.DateTime) *string

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

func PtrFormat[T any](v *T, formatter func(T) string) *string

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

func StringToInt[T Int](s string) T

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.

Types

type Int added in v0.19.4

type Int interface {
	int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr
}

Jump to

Keyboard shortcuts

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