utils

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindChangedFieldsSimple

func FindChangedFieldsSimple[T any](original, updated *T, info *schema.ModelInfo) (map[string]interface{}, error)

FindChangedFieldsSimple compares two structs (original and updated) using cached metadata for optimized comparison. It requires access to internal/schema types, so it lives in utils for now but could potentially be moved if dependencies change.

func IsZero

func IsZero(v reflect.Value) bool

IsZero checks if a reflect.Value is the zero value for its type. This handles various kinds including structs, slices, maps, pointers, and primitives.

func NewPtr

func NewPtr[T any]() T

NewPtr returns a non-nil, zero-initialized value of type T (where T is a pointer type).

func NormalizeValue

func NormalizeValue(value interface{}) interface{}

NormalizeValue recursively normalizes a value for consistent JSON marshaling. This is necessary to ensure a consistent cache key regardless of how the value was constructed.

func RegisterTypeRecursive added in v0.1.12

func RegisterTypeRecursive(t reflect.Type)

RegisterTypeRecursive registers the given type and all its fields recursively with gob.Register. It avoids duplicate registration by using the fully qualified type name as key. It also recovers from gob.Register panic to prevent test crash.

func ToPtr

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

ToPtr returns a pointer to the given value (if not already a pointer)

func ToSnakeCase added in v0.1.2

func ToSnakeCase(str string) string

ToSnakeCase converts a string from CamelCase or PascalCase to snake_case.

Types

type OrderedMap

type OrderedMap struct {
	// contains filtered or unexported fields
}

OrderedMap is a map that preserves key insertion order and supports JSON serialization.

func NewOrderedMap

func NewOrderedMap() *OrderedMap

NewOrderedMap creates a new empty OrderedMap.

func (*OrderedMap) Get

func (om *OrderedMap) Get(key string) (interface{}, bool)

Get retrieves the value for a key.

func (*OrderedMap) Keys

func (om *OrderedMap) Keys() []string

Keys returns the keys in insertion order.

func (*OrderedMap) MarshalJSON

func (om *OrderedMap) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler, outputting keys in order.

func (*OrderedMap) Set

func (om *OrderedMap) Set(key string, value interface{})

Set sets the value for a key, preserving insertion order.

Jump to

Keyboard shortcuts

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