Help us shape the future of Go! Take the 2026 Go Developer Survey

interfacetricks

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(value interface{}) interface{}

Create a copy of a value, so we can modify it in place.

func CopyObject added in v0.27.0

func CopyObject(in map[string]interface{}) map[string]interface{}

Utility so we don't need to cast.

func Equal

func Equal(left interface{}, right interface{}) bool

Recursively test equality of two value trees.

func Extract added in v0.27.0

func Extract(src interface{}, dst interface{}) []error

Extract "deserializes" an interface into a target destination, using the "encoding/json" conventions.

No actual serialization happens, which means we can avoid a lot of string copies.

The extraction will try to continue even when errors are encountered and return detailed error information for each problem.

func IntersectWith

func IntersectWith(
	left interface{},
	right interface{},
	resolve func(l interface{}, r interface{}) interface{},
) interface{}

Create a new object or array containing only the parts that were in both trees. The values in the new tree are determined by the resolve argument.

func Merge

func Merge(left interface{}, right interface{}) interface{}

Merges two value trees recursively. If there is a conflict, the right value is retained.

func MergeObjects

func MergeObjects(left map[string]interface{}, right map[string]interface{}) map[string]interface{}

Like `Merge` but has a more useful return type if you're merging objects.

func MergeWith

func MergeWith(
	left interface{},
	right interface{},
	conflict func(interface{}, interface{}) interface{},
) interface{}

MergeWith is like Merge but allows you to customize what happens on a conflict.

func TopDownWalk

func TopDownWalk(w TopDownWalker, value interface{}) interface{}

Types

type ExtractError added in v0.27.0

type ExtractError struct {
	SrcPath []interface{}
	SrcType reflect.Type
	DstType reflect.Type
}

func (ExtractError) Error added in v0.27.0

func (e ExtractError) Error() string

type TopDownWalker

type TopDownWalker interface {
	WalkArray([]interface{}) (interface{}, bool)
	WalkObject(map[string]interface{}) (interface{}, bool)

	WalkString(string) (interface{}, bool)
	WalkBool(bool) (interface{}, bool)
}

This is a utility for recursively transforming JSON-like interface values in go.

At every step, the transformer returns the new value as well as an indication of whether or not we should continue.

Jump to

Keyboard shortcuts

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