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

picker

package
v0.40.6 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 11 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidModifierData = errors.New("failed to apply some of the field modifiers for the provided data")
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).

In case some data fails to apply against the registered modifiers a wrapped ErrInvalidModifierData is returned that you can inspect and decide to ignore or propagate further up the execution chain.

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