interfacetricks

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

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

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

func (ExtractError) Error

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