picker

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Modifiers = map[string]ModifierFactoryFunc{}

Functions

func Pick

func Pick(data any, rawFields string) (any, error)

Pick converts data into a []any, map[string]any, etc. (using json marshal->unmarshal) containing only the fields from the parsed rawFields expression.

rawFields is a comma separated string of the fields to include. Nested fields should be listed with dot-notation. Fields value modifiers are also supported using the `:modifier(args)` format (see Modifiers).

Example:

data := map[string]any{"a": 1, "b": 2, "c": map[string]any{"c1": 11, "c2": 22}}
Pick(data, "a,c.c1") // map[string]any{"a": 1, "c": map[string]any{"c1": 11}}

Types

type Modifier

type Modifier interface {
	// Modify executes the modifier and returns a new modified value.
	Modify(value any) (any, error)
}

type ModifierFactoryFunc

type ModifierFactoryFunc func(args ...string) (Modifier, error)

Jump to

Keyboard shortcuts

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