core

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: Apache-2.0 Imports: 9 Imported by: 113

Documentation

Index

Constants

View Source
const MaxArgs = 65536

Variables

View Source
var (
	ErrMissedArgument        = errors.New("missed argument")
	ErrInvalidArgument       = errors.New("invalid argument")
	ErrInvalidArgumentNumber = errors.New("invalid argument number")
	ErrInvalidType           = errors.New("invalid type")
	ErrInvalidOperation      = errors.New("invalid operation")
	ErrNotFound              = errors.New("not found")
	ErrNotUnique             = errors.New("not unique")
	ErrTerminated            = errors.New("operation is terminated")
	ErrUnexpected            = errors.New("unexpected error")
	ErrTimeout               = errors.New("operation timed out")
	ErrNotImplemented        = errors.New("not implemented")
	ErrNotSupported          = errors.New("not supported")
	ErrNoMoreData            = errors.New("no more data")
)

Functions

func Error

func Error(err error, msg string) error

func Errorf added in v0.4.0

func Errorf(err error, format string, args ...interface{}) error

func Errors

func Errors(err ...error) error

func ForEach added in v0.12.0

func ForEach(ctx context.Context, iter Iterator, predicate func(value Value, key Value) bool) error

func IsNil

func IsNil(input interface{}) bool

func IsNoMoreData added in v0.8.0

func IsNoMoreData(err error) bool

func IsTypeOf

func IsTypeOf(value Value, check Type) bool

IsTypeOf return true when value's type is equal to check type. Returns false, otherwise.

func NewRootScope

func NewRootScope() (*Scope, CloseFunc)

func NumberBoundaries added in v0.8.0

func NumberBoundaries(input float64) (max float64, min float64)

func NumberLowerBoundary added in v0.9.0

func NumberLowerBoundary(input float64) float64

func NumberUpperBoundary added in v0.9.0

func NumberUpperBoundary(input float64) float64

func ParamsFrom

func ParamsFrom(ctx context.Context) (map[string]Value, error)

func ParamsWith

func ParamsWith(ctx context.Context, params map[string]Value) context.Context

func Random added in v0.8.0

func Random(max float64, min float64) float64

func SourceError

func SourceError(src SourceMap, err error) error

func TypeError

func TypeError(actual Type, expected ...Type) error

func ValidateArgs

func ValidateArgs(args []Value, minimum, maximum int) error

func ValidateType

func ValidateType(value Value, required ...Type) error

ValidateType checks the match of value's type and required types.

func ValidateValueTypePairs added in v0.5.0

func ValidateValueTypePairs(pairs ...PairValueType) error

ValidateValueTypePairs validate pairs of Values and Types. Returns error when type didn't match

Types

type BaseType added in v0.7.0

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

func (BaseType) Equals added in v0.7.0

func (t BaseType) Equals(other Type) bool

func (BaseType) ID added in v0.7.0

func (t BaseType) ID() int64

func (BaseType) String added in v0.7.0

func (t BaseType) String() string

type Cloneable

type Cloneable interface {
	Value
	Clone() Cloneable
}

type CloseFunc

type CloseFunc func() error

type Expression

type Expression interface {
	Exec(ctx context.Context, scope *Scope) (Value, error)
}

type Function

type Function = func(ctx context.Context, args ...Value) (Value, error)

Function is a common interface for all functions of FQL.

type Functions added in v0.8.0

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

Functions is a container for functions.

func NewFunctions added in v0.10.0

func NewFunctions() *Functions

NewFunctions returns new empty Functions.

func NewFunctionsFromMap added in v0.10.0

func NewFunctionsFromMap(funcs map[string]Function) *Functions

NewFunctionsFromMap creates new Functions from map, where key is the name of the function and value is the function.

func (*Functions) Get added in v0.10.0

func (fns *Functions) Get(name string) (Function, bool)

Get returns the function with the given name. If the function does not exist it returns nil, false.

func (*Functions) Names added in v0.10.0

func (fns *Functions) Names() []string

Names returns the names of the internal functions.

func (*Functions) Set added in v0.10.0

func (fns *Functions) Set(name string, fn Function)

Set sets the function with the given name. If the function with the such name already exists it will be overwritten.

func (*Functions) Unset added in v0.10.0

func (fns *Functions) Unset(name string)

Unset delete the function with the given name.

type Getter added in v0.6.0

type Getter interface {
	GetIn(ctx context.Context, path []Value) (Value, error)
}

Getter represents an interface of complex types that needs to be used to read values by path. The interface is created to let user-defined types be used in dot notation data access.

type Iterable added in v0.7.0

type Iterable interface {
	Iterate(ctx context.Context) (Iterator, error)
}

Iterable represents an interface of a value that can be iterated by using an iterator.

type Iterator added in v0.7.0

type Iterator interface {
	Next(ctx context.Context) (value Value, key Value, err error)
}

Iterator represents an interface of a value iterator. When iterator is exhausted it must return None as a value.

type Namespace added in v0.8.0

type Namespace interface {
	Namespace(name string) Namespace
	RegisterFunction(name string, fun Function) error
	RegisterFunctions(funs *Functions) error
	RegisteredFunctions() []string
	RemoveFunction(name string)
}

type OperatorExpression

type OperatorExpression interface {
	Expression
	Eval(ctx context.Context, left, right Value) (Value, error)
}

type PairValueType added in v0.5.0

type PairValueType struct {
	Value Value
	Types []Type
}

PairValueType is a supporting structure that used in validateValueTypePairs.

func NewPairValueType added in v0.10.0

func NewPairValueType(value Value, types ...Type) PairValueType

NewPairValueType it's a shortcut for creating a new PairValueType.

The common pattern of using PairValueType is: ```

pairs := []core.PairValueType{
    core.PairValueType{args[0], []core.Type{types.String}},               // go vet warning
    core.PairValueType{Value: args[1], Types: []core.Type{types.Binary}}, // too long
}

``` With NewPairValueType there is no need to type `[]core.Type{...}` and code becomes more readable and maintainable.

That is how the code above looks like with NewPairValueType: ```

pairs := []core.PairValueType{
    core.NewPairValueType(args[0], types.String),
    core.NewPairValueType(args[1], types.Binary),
}

```

type RootScope added in v0.5.0

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

func (*RootScope) AddDisposable added in v0.5.0

func (s *RootScope) AddDisposable(disposable io.Closer)

func (*RootScope) Close added in v0.5.0

func (s *RootScope) Close() error

type Scope

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

func (*Scope) Fork

func (s *Scope) Fork() *Scope

func (*Scope) GetVariable

func (s *Scope) GetVariable(name string) (Value, error)

func (*Scope) HasVariable

func (s *Scope) HasVariable(name string) bool

func (*Scope) MustGetVariable added in v0.5.0

func (s *Scope) MustGetVariable(name string) Value

func (*Scope) SetVariable

func (s *Scope) SetVariable(name string, val Value) error

func (*Scope) UpdateVariable added in v0.5.0

func (s *Scope) UpdateVariable(name string, val Value) error

type Setter added in v0.6.0

type Setter interface {
	SetIn(ctx context.Context, path []Value, value Value) error
}

Setter represents an interface of complex types that needs to be used to write values by path. The interface is created to let user-defined types be used in dot notation assignment.

type SourceMap

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

func NewSourceMap

func NewSourceMap(text string, line, col int) SourceMap

func (SourceMap) Column

func (s SourceMap) Column() int

func (SourceMap) Line

func (s SourceMap) Line() int

func (SourceMap) String

func (s SourceMap) String() string

type Type

type Type interface {
	ID() int64
	String() string
	Equals(other Type) bool
}

func NewType added in v0.7.0

func NewType(name string) Type

type Value

type Value interface {
	json.Marshaler
	Type() Type
	String() string
	Compare(other Value) int64
	Unwrap() interface{}
	Hash() uint64
	Copy() Value
}

Value represents an interface of any type that needs to be used during runtime

func ParamFrom

func ParamFrom(ctx context.Context, name string) (Value, error)

Jump to

Keyboard shortcuts

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