core

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareValues

func CompareValues(v1, v2 reflect.Value, op string, ignoreCase bool) (bool, error)

func ConvertValue

func ConvertValue(v reflect.Value, targetType reflect.Type) reflect.Value

func Copy

func Copy[T any](src T, opts ...CopyOption) (T, error)

Copy creates a deep copy of src. It returns the copy and a nil error in case of success and the zero value for the type and a non-nil error on failure.

It correctly handles cyclic references and unexported fields.

func DeepCopyValue

func DeepCopyValue(v reflect.Value) reflect.Value

func Dereference

func Dereference(v reflect.Value) (reflect.Value, error)

func Equal

func Equal[T any](a, b T, opts ...EqualOption) bool

Equal performs a deep equality check between a and b.

func EscapeKey

func EscapeKey(key string) string

func ExtractKey

func ExtractKey(v reflect.Value, fieldIdx int) any

func GetKeyField

func GetKeyField(typ reflect.Type) (int, bool)

func InterfaceToValue

func InterfaceToValue(i any) reflect.Value

func JoinPath

func JoinPath(parent, child string) string

JoinPath joins two JSON Pointer paths with a slash.

func MustCopy

func MustCopy[T any](src T, opts ...CopyOption) T

MustCopy creates a deep copy of src. It returns the copy on success or panics in case of any failure.

It correctly handles cyclic references and unexported fields.

func NormalizePath

func NormalizePath(path string) string

NormalizePath converts a dot-notation or JSON Pointer path to a standard JSON Pointer.

func RegisterCustomCopy

func RegisterCustomCopy(typ reflect.Type, fn reflect.Value)

RegisterCustomCopy registers a custom copy function for a specific type. The function must be of type func(src T) (T, error).

func RegisterCustomEqual

func RegisterCustomEqual(typ reflect.Type, fn reflect.Value)

RegisterCustomEqual registers a custom equality function for a specific type. The function must be of type func(a, b T) bool.

func SetValue

func SetValue(v, newVal reflect.Value)

func ToReflectValue

func ToReflectValue(v any) reflect.Value

func ValueEqual

func ValueEqual(a, b reflect.Value, config *equalConfig) bool

ValueEqual performs a deep equality check between two reflect.Values.

func ValueToInterface

func ValueToInterface(v reflect.Value) any

Types

type Copier

type Copier[T any] interface {
	// Copy returns a deep copy of the receiver.
	Copy() (T, error)
}

Copier is an interface that types can implement to provide their own custom deep copy logic. The type T in Copy() (T, error) must be the same concrete type as the receiver that implements this interface.

type CopyOption

type CopyOption interface {
	// contains filtered or unexported methods
}

CopyOption allows configuring the behavior of the Copy function.

func CopyIgnorePath

func CopyIgnorePath(path string) CopyOption

CopyIgnorePath returns an option that tells Copy to ignore the specified path. The ignored path will have the zero value for its type in the resulting copy.

func SkipUnsupported

func SkipUnsupported() CopyOption

SkipUnsupported returns an option that tells Copy to skip unsupported types (like non-nil functions or channels) instead of returning an error.

type DeepPath

type DeepPath string

DeepPath represents a path to a field or element within a structure. It supports JSON Pointers (RFC 6901) syntax like "/Field/SubField".

func (DeepPath) Delete

func (p DeepPath) Delete(v reflect.Value) error

func (DeepPath) Navigate

func (p DeepPath) Navigate(v reflect.Value, parts []PathPart) (reflect.Value, PathPart, error)

func (DeepPath) Resolve

func (p DeepPath) Resolve(v reflect.Value) (reflect.Value, error)

Resolve traverses v using the path and returns the reflect.Value found.

func (DeepPath) ResolveParent

func (p DeepPath) ResolveParent(v reflect.Value) (reflect.Value, PathPart, error)

func (DeepPath) ResolveParentPath

func (p DeepPath) ResolveParentPath() (DeepPath, PathPart, error)

ResolveParentPath splits the path into parent path and the last part.

func (DeepPath) Set

func (p DeepPath) Set(v reflect.Value, val reflect.Value) error

func (DeepPath) StripParts

func (p DeepPath) StripParts(prefix []PathPart) DeepPath

type EqualOption

type EqualOption interface {
	// contains filtered or unexported methods
}

EqualOption allows configuring the behavior of the Equal function.

func EqualIgnorePath

func EqualIgnorePath(path string) EqualOption

EqualIgnorePath returns an option that tells Equal to ignore the specified path.

type FieldInfo

type FieldInfo struct {
	Index int
	Name  string
	Tag   StructTag
}

type PathPart

type PathPart struct {
	Key     string
	Index   int
	IsIndex bool
}

func ParseJSONPointer

func ParseJSONPointer(path string) []PathPart

func ParsePath

func ParsePath(path string) []PathPart

ParsePath parses a JSON Pointer path. It assumes the path starts with "/" or is empty.

func (PathPart) Equals

func (p PathPart) Equals(other PathPart) bool

type StructTag

type StructTag struct {
	Ignore   bool
	ReadOnly bool
	Atomic   bool
	Key      bool
}

func ParseTag

func ParseTag(field reflect.StructField) StructTag

type TypeInfo

type TypeInfo struct {
	Fields        []FieldInfo
	KeyFieldIndex int
}

func GetTypeInfo

func GetTypeInfo(typ reflect.Type) *TypeInfo

type VisitKey

type VisitKey struct {
	A, B uintptr
	Typ  reflect.Type
}

Jump to

Keyboard shortcuts

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