selector

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package selector contains a selector library for JSON and Protobuf. It's in its own standalone package only to avoid circular dependencies

nolint:govet

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnSelector

type ColumnSelector struct {
	MetaKey  *string
	Selector Selector
}

func ParseColumnSelector

func ParseColumnSelector(str string) (ColumnSelector, error)

ParseColumnSelector parses a selector expression into an executable ColumnSelector.

func (*ColumnSelector) Select

func (s *ColumnSelector) Select(meta map[string]interface{}, body interface{}) (interface{}, error)

func (ColumnSelector) String

func (s ColumnSelector) String() string

type ColumnSelectorAST

type ColumnSelectorAST struct {
	MetaKey *string      `( "meta" "(" @String ")" |`
	Field   *string      `  @Ident )`
	Index   []*Index     `( "[" @@ "]" )*`
	Next    *SelectorAST `("." @@)?`
}

func (*ColumnSelectorAST) ToSelector

func (s *ColumnSelectorAST) ToSelector() ColumnSelector

type ErrNotFound

type ErrNotFound struct {
	// contains filtered or unexported fields
}

ErrNotFound is returned when the selector references an invalid field

func (*ErrNotFound) Error

func (e *ErrNotFound) Error() string

Error returns the formatted error string

type Index

type Index struct {
	Number *int    `@Number |`
	String *string `@String`
}

type Path

type Path struct {
	Field       *string
	NumberIndex *int
}

type Selector

type Selector []Path

Selector is a protobuf path selector.

func ParseSelector

func ParseSelector(str string) (Selector, error)

ParseSelector parses a selector expression into an executable Selector.

func (Selector) Select

func (s Selector) Select(v interface{}) (interface{}, error)

Select evaluates the selector expression against the given value. The only supported types are

map[string]interface{}
[]interface{}
google.golang.org/protobuf/reflect.Message

func (Selector) SelectProto

func (s Selector) SelectProto(msg pref.Message) (interface{}, error)

SelectProto returns the referenced value from the protobuf message. Adhering to Golang protobuf behavior, if a selector references nested value of a nil message, the default Go value will be returned. Array out of index will still panic. ErrNotFound is returned if a non-existing field is referenced. Other errors may be returned on failed type conversion. nolint: gocyclo

func (Selector) String

func (s Selector) String() string

type SelectorAST

type SelectorAST struct {
	Field string       `@Ident`
	Index []*Index     `( "[" @@ "]" )*`
	Next  *SelectorAST `("." @@)?`
}

func (*SelectorAST) ToSelector

func (a *SelectorAST) ToSelector() Selector

Jump to

Keyboard shortcuts

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