mapx

package
v0.63.8 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PathSeparator = "."
)

Variables

This section is empty.

Functions

func EscapeDots added in v0.54.2

func EscapeDots(s string) string

EscapeDots escapes all dots in the string with a backslash so they won't be treated as path separators

func MapStructBoolSliceCaster added in v0.21.3

func MapStructBoolSliceCaster(_ reflect.Type, value any) (any, error)

func MapStructDurationCaster

func MapStructDurationCaster(targetType reflect.Type, value any) (any, error)

MapStructDurationCaster casts values to time.Duration or *time.Duration based on target type. For *time.Duration: empty strings result in a nil pointer. For both: non-empty strings are parsed using cast.ToDurationE.

func MapStructFloat32SliceCaster added in v0.21.3

func MapStructFloat32SliceCaster(_ reflect.Type, value any) (any, error)

func MapStructFloat64SliceCaster added in v0.21.3

func MapStructFloat64SliceCaster(_ reflect.Type, value any) (any, error)

func MapStructInt64SliceCaster added in v0.21.3

func MapStructInt64SliceCaster(_ reflect.Type, value any) (any, error)

func MapStructIntSliceCaster added in v0.21.3

func MapStructIntSliceCaster(_ reflect.Type, value any) (any, error)

func MapStructJSONCaster added in v0.63.8

func MapStructJSONCaster(targetType reflect.Type, value any) (any, error)

MapStructJSONCaster casts JSON strings or bytes to map fields.

func MapStructSliceCaster added in v0.21.3

func MapStructSliceCaster(targetType reflect.Type, value any) (any, error)

MapStructSliceCaster casts values to []T, based on casters in mapStructSliceCasters

func MapStructStringSliceCaster added in v0.21.3

func MapStructStringSliceCaster(_ reflect.Type, value any) (any, error)

func MapStructTimeCaster

func MapStructTimeCaster(targetType reflect.Type, value any) (any, error)

MapStructTimeCaster casts string values to time.Time or *time.Time based on target type. For *time.Time: empty strings result in a nil pointer. For both: non-empty strings are parsed using cast.ToTimeE.

func SkipExisting

func SkipExisting(mode *OpMode)

func SnakeCaseMatchName added in v0.54.6

func SnakeCaseMatchName(mapKey, fieldName string) bool

SnakeCaseMatchName matches snake_case map keys to PascalCase/camelCase field names. The comparison is case-insensitive after converting the map key to PascalCase.

Examples:

  • "user_id" matches "UserId", "userId", "UserID"
  • "created_at" matches "CreatedAt"
  • "api_token" matches "ApiToken"

func SplitUnescapedDotN added in v0.51.6

func SplitUnescapedDotN(s string, n int) []string

Types

type MapOption

type MapOption func(mode *OpMode)

type MapStructCaster

type MapStructCaster func(targetType reflect.Type, value any) (any, error)

type MapStructDecoder

type MapStructDecoder func(targetType reflect.Type, val any) (any, error)

type MapX

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

func NewMapX

func NewMapX(msis ...map[string]any) *MapX

func (*MapX) Append

func (m *MapX) Append(key string, values ...any) error

func (*MapX) Get

func (m *MapX) Get(key string) *MapXNode

func (*MapX) Has

func (m *MapX) Has(key string) bool

func (*MapX) Keys

func (m *MapX) Keys() []string

func (*MapX) Merge

func (m *MapX) Merge(key string, source any, options ...MapOption)

func (*MapX) Msi

func (m *MapX) Msi() map[string]any

func (*MapX) Set

func (m *MapX) Set(key string, value any, options ...MapOption)

func (*MapX) String

func (m *MapX) String() string

type MapXNode

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

func (*MapXNode) Data

func (n *MapXNode) Data() any

func (*MapXNode) IsMap

func (n *MapXNode) IsMap() bool

func (*MapXNode) Map

func (n *MapXNode) Map() (*MapX, error)

func (*MapXNode) Msi

func (n *MapXNode) Msi() (map[string]any, error)

func (*MapXNode) Slice

func (n *MapXNode) Slice() ([]any, error)

func (*MapXNode) StringSlice

func (n *MapXNode) StringSlice() ([]string, error)

type Msier

type Msier interface {
	Msi() map[string]any
}

type OpMode

type OpMode struct {
	IsSet        bool
	SkipExisting bool
}

type Struct

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

func NewStruct

func NewStruct(source any, settings *StructSettings) (*Struct, error)

func (*Struct) Keys

func (s *Struct) Keys() []StructKey

func (*Struct) Read

func (s *Struct) Read() (*MapX, error)

func (*Struct) ReadNonZero added in v0.48.0

func (s *Struct) ReadNonZero() (*MapX, error)

func (*Struct) ReadZeroAndDefaultValues

func (s *Struct) ReadZeroAndDefaultValues() (zeros *MapX, defaults *MapX, err error)

func (*Struct) Write

func (s *Struct) Write(values *MapX) error

type StructKey

type StructKey struct {
	Parent  string
	Key     string
	Kind    reflect.Kind
	SubKeys []StructKey
}

func (StructKey) String

func (k StructKey) String() string

type StructSettings

type StructSettings struct {
	FieldTag           string
	DefaultTag         string
	Casters            []MapStructCaster
	Decoders           []MapStructDecoder
	MatchName          func(mapKey, fieldName string) bool
	DefaultToFieldName bool
}

type StructTag

type StructTag struct {
	Name     string
	NoCast   bool
	NoDecode bool
	Prefix   string
}

Jump to

Keyboard shortcuts

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