picker
import picker "ganigeorgiev.com/pocketbase/pocketbase/tools/picker"
Source: tools/picker.
Variables
var ErrInvalidModifierData = errors.New("failed to apply some of the field modifiers for the provided data")
var Modifiers = map[string]ModifierFactoryFunc{}
Functions
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
Modifier
type Modifier interface {
// Modify executes the modifier and returns a new modified value.
Modify(value any) (any, error)
}
ModifierFactoryFunc
type ModifierFactoryFunc func(args ...string) (Modifier, error)
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.