utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 9 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBoolean

func DecodeBoolean(value any) (bool, error)

DecodeBoolean tries to convert an unknown value to a bool value

func DecodeDateTime

func DecodeDateTime(value any) (time.Time, error)

DecodeDateTime tries to convert an unknown value to a time.Time value

func DecodeDuration

func DecodeDuration(value any) (time.Duration, error)

DecodeDuration tries to convert an unknown value to a duration value

func DecodeFloat

func DecodeFloat[T float32 | float64](value any) (T, error)

DecodeFloat tries to convert an unknown value to a float value

func DecodeInt

func DecodeInt[T int | int8 | int16 | int32 | int64](value any) (T, error)

DecodeInt tries to convert an unknown value to a not-null integer value

func DecodeNullableBoolean

func DecodeNullableBoolean(value any) (*bool, error)

DecodeNullableBoolean tries to convert an unknown value to a bool pointer

func DecodeNullableDateTime

func DecodeNullableDateTime(value any) (*time.Time, error)

DecodeNullableDateTime tries to convert an unknown value to a time.Time pointer

func DecodeNullableDuration

func DecodeNullableDuration(value any) (*time.Duration, error)

DecodeNullableDuration tries to convert an unknown value to a duration pointer

func DecodeNullableFloat

func DecodeNullableFloat[T float32 | float64](value any) (*T, error)

DecodeNullableFloat tries to convert an unknown value to a float pointer

func DecodeNullableInt

func DecodeNullableInt[T int | int8 | int16 | int32 | int64](value any) (*T, error)

DecodeNullableInt tries to convert an unknown value to a nullable integer

func DecodeNullableObjectValue

func DecodeNullableObjectValue(target any, object map[string]any, key string) error

DecodeNullableObjectValue get and decode a nullable value from object by key

func DecodeNullableString

func DecodeNullableString(value any) (*string, error)

DecodeNullableString tries to convert an unknown value to a string pointer

func DecodeNullableUint

func DecodeNullableUint[T uint | uint8 | uint16 | uint32 | uint64](value any) (*T, error)

DecodeNullableUint tries to convert an unknown value to a nullable unsigned integer pointer

func DecodeNullableValue

func DecodeNullableValue(target any, value any, decodeHooks ...mapstructure.DecodeHookFunc) error

DecodeNullableValue tries to convert and set an unknown value into the target, fallback to mapstructure decoder

func DecodeObjectValue

func DecodeObjectValue(target any, object map[string]any, key string) error

DecodeObjectValue get and decode a value from object by key

func DecodeString

func DecodeString(value any) (string, error)

DecodeString tries to convert an unknown value to a string value

func DecodeUint

func DecodeUint[T uint | uint8 | uint16 | uint32 | uint64](value any) (T, error)

DecodeUint tries to convert an unknown value to an unsigned integer value

func DecodeValue

func DecodeValue(target any, value any, decodeHooks ...mapstructure.DecodeHookFunc) error

DecodeValue tries to convert and set an unknown value into the target, the value must not be null fallback to mapstructure decoder

func EncodeMap

func EncodeMap[T MapEncoder](input T) map[string]any

EncodeMap encodes an object to a map[string]any, using json tag to convert object keys

func EncodeMaps

func EncodeMaps[T MapEncoder](inputs []T) []map[string]any

EncodeMaps encode objects to a slice of map[string]any, using json tag to convert object keys

func EncodeNullableMaps

func EncodeNullableMaps[T MapEncoder](inputs *[]T) []map[string]any

EncodeNullableMaps encode objects to a slice of map[string]any, using json tag to convert object keys

func EncodeObject

func EncodeObject(input any) (map[string]any, error)

EncodeObject encodes an unknown type to a map[string]any, using json tag to convert object keys

func EncodeObjectSlice

func EncodeObjectSlice[T any](input []T) ([]map[string]any, error)

EncodeObjectSlice encodes array of unknown type to map[string]any slice, using json tag to convert object keys

func EncodeObjectWithColumnSelection

func EncodeObjectWithColumnSelection[T any](fields map[string]schema.Field, data T) (map[string]any, error)

EncodeObjectWithColumnSelection encodes an object with column fields selection without relationship

func EncodeObjects

func EncodeObjects(input any) ([]map[string]any, error)

EncodeObjects encodes an object rows to a slice of map[string]any, using json tag to convert object keys

func EncodeObjectsWithColumnSelection

func EncodeObjectsWithColumnSelection[T any](fields map[string]schema.Field, data []T) ([]map[string]any, error)

EncodeObjectsWithColumnSelection encodes objects with column fields selection without relationship

func EvalNestedColumnArray

func EvalNestedColumnArray(fields *schema.NestedArray, value any) (any, error)

EvalNestedColumnArray evaluate and prune nested fields from array without relationship

func EvalNestedColumnArrayIntoSlice

func EvalNestedColumnArrayIntoSlice[T any](fields *schema.NestedArray, value []T) (any, error)

EvalNestedColumnArrayIntoSlice evaluate and prune nested fields from array without relationship

func EvalNestedColumnFields

func EvalNestedColumnFields(fields schema.NestedField, value any) (any, error)

EvalNestedColumnFields evaluate and prune nested fields without relationship

func EvalNestedColumnObject

func EvalNestedColumnObject(fields *schema.NestedObject, value any) (any, error)

EvalNestedColumnObject evaluate and prune nested fields from an object without relationship

func EvalObjectWithColumnSelection

func EvalObjectWithColumnSelection(fields map[string]schema.Field, data map[string]any) (map[string]any, error)

EvalObjectWithColumnSelection evaluate and prune column fields without relationship

func EvalObjectsWithColumnSelection

func EvalObjectsWithColumnSelection(fields map[string]schema.Field, data []map[string]any) ([]map[string]any, error)

EvalObjectsWithColumnSelection evaluate and prune column fields of array objects without relationship

func GetAny

func GetAny(object map[string]any, key string) (any, bool)

GetAny get an unknown value from object by key

func GetBool

func GetBool(object map[string]any, key string) (bool, error)

GetBool get a bool value from object by key

func GetDateTime

func GetDateTime(object map[string]any, key string) (time.Time, error)

GetDateTime get a time.Time value from object by key

func GetDuration

func GetDuration(object map[string]any, key string) (time.Duration, error)

GetDuration get a time.Duration value from object by key

func GetFloat

func GetFloat[T float32 | float64](object map[string]any, key string) (T, error)

GetFloat get a float value from object by key

func GetInt

func GetInt[T int | int8 | int16 | int32 | int64](object map[string]any, key string) (T, error)

GetInt get an integer value from object by key

func GetNullableBool

func GetNullableBool(object map[string]any, key string) (*bool, error)

GetNullableBool get a bool pointer from object by key

func GetNullableDateTime

func GetNullableDateTime(object map[string]any, key string) (*time.Time, error)

GetNullableDateTime get a time.Time pointer from object by key

func GetNullableDuration

func GetNullableDuration(object map[string]any, key string) (*time.Duration, error)

GetNullableDuration get a time.Duration pointer from object by key

func GetNullableFloat

func GetNullableFloat[T float32 | float64](object map[string]any, key string) (*T, error)

GetNullableFloat get a float pointer from object by key

func GetNullableInt

func GetNullableInt[T int | int8 | int16 | int32 | int64](object map[string]any, key string) (*T, error)

GetNullableInt get an integer pointer from object by key

func GetNullableString

func GetNullableString(object map[string]any, key string) (*string, error)

GetNullableString get a string pointer from object by key

func GetNullableUint

func GetNullableUint[T uint | uint8 | uint16 | uint32 | uint64](object map[string]any, key string) (*T, error)

GetNullableUint get an unsigned integer pointer from object by key

func GetString

func GetString(object map[string]any, key string) (string, error)

GetString get a bool value from object by key

func GetUint

func GetUint[T uint | uint8 | uint16 | uint32 | uint64](object map[string]any, key string) (T, error)

GetUint get an unsigned integer value from object by key

func IsNil

func IsNil(value any) bool

IsNil a safe function to check null value

func ResolveArgumentVariables

func ResolveArgumentVariables(arguments map[string]schema.Argument, variables map[string]any) (map[string]any, error)

ResolveArgumentVariables resolve variables in arguments if exist

func ToPtr

func ToPtr[V any](value V) *V

ToPtr converts a value to its pointer

Types

type MapEncoder

type MapEncoder interface {
	ToMap() map[string]any
}

MapEncoder abstracts a type with the ToMap method to encode type to map

type ObjectDecoder

type ObjectDecoder interface {
	FromValue(value map[string]any) error
}

ObjectDecoder abstracts a type with the FromValue method to decode an object value

type Scalar

type Scalar interface {
	ScalarName() string
}

Scalar abstracts a scalar interface to determine when evaluating

type ValueDecoder

type ValueDecoder interface {
	FromValue(value any) error
}

ValueDecoder abstracts a type with the FromValue method to decode any value

Jump to

Keyboard shortcuts

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