parse

package
v1.2.3-fred.6 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: Apache-2.0 Imports: 10 Imported by: 24

Documentation

Overview

TODO(awly): combine Expression and Matcher. It should be possible to write: `{{regexp.match(email.local(external.trait_name))}}`

Index

Constants

View Source
const (
	// LiteralNamespace is a namespace for Expressions that always return
	// static literal values.
	LiteralNamespace = "literal"
	// EmailNamespace is a function namespace for email functions
	EmailNamespace = "email"
	// EmailLocalFnName is a name for email.local function
	EmailLocalFnName = "local"
	// RegexpNamespace is a function namespace for regexp functions.
	RegexpNamespace = "regexp"
	// RegexpMatchFnName is a name for regexp.match function.
	RegexpMatchFnName = "match"
	// RegexpNotMatchFnName is a name for regexp.not_match function.
	RegexpNotMatchFnName = "not_match"
	// RegexpReplaceFnName is a name for regexp.replace function.
	RegexpReplaceFnName = "replace"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Expression

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

Expression is an expression template that can interpolate to some variables

func NewExpression

func NewExpression(variable string) (*Expression, error)

NewExpression parses expressions like {{external.foo}} or {{internal.bar}}, or a literal value like "prod". Call Interpolate on the returned Expression to get the final value based on traits or other dynamic values.

func (*Expression) Interpolate

func (p *Expression) Interpolate(traits map[string][]string) ([]string, error)

Interpolate interpolates the variable adding prefix and suffix if present, returns trace.NotFound in case if the trait is not found, nil in case of success and BadParameter error otherwise

func (*Expression) Name

func (p *Expression) Name() string

Name returns variable name

func (*Expression) Namespace

func (p *Expression) Namespace() string

Namespace returns a variable namespace, e.g. external or internal

type Matcher

type Matcher interface {
	Match(in string) bool
}

Matcher matches strings against some internal criteria (e.g. a regexp)

func NewAnyMatcher

func NewAnyMatcher(in []string) (Matcher, error)

NewAnyMatcher returns a matcher function based on incoming values

func NewMatcher

func NewMatcher(value string) (m Matcher, err error)

NewMatcher parses a matcher expression. Currently supported expressions: - string literal: `foo` - wildcard expression: `*` or `foo*bar` - regexp expression: `^foo$` - regexp function calls:

  • positive match: `{{regexp.match("foo.*")}}`
  • negative match: `{{regexp.not_match("foo.*")}}`

These expressions do not support variable interpolation (e.g. `{{internal.logins}}`), like Expression does.

type MatcherFn

type MatcherFn func(in string) bool

MatcherFn converts function to a matcher interface

func (MatcherFn) Match

func (fn MatcherFn) Match(in string) bool

Match matches string against a regexp

Jump to

Keyboard shortcuts

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