Documentation
¶
Index ¶
- Variables
- func IndexFuncArg[T any](args map[string]any, name string) (T, error)
- func IndexKV(m KV, key string) (any, bool)
- func SetDebugLevel(level int)
- func SetDebugWriter(w io.Writer)
- func SetErrorVerbose(verbose bool)
- type ArrayValue
- type Ctx
- type ErrInvalidFunctionArg
- type ErrMissingFields
- type FieldValue
- type Function
- type FunctionArg
- type FunctionValue
- type HexString
- type KV
- type LiteralValue
- type ParseError
- type Result
- type Rule
- type RuleFunc
- type ValueParseError
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidOperation = errors.New("invalid operation")
View Source
var StdlibFuncs = map[string]*Function{ "starts_with": { Args: []FunctionArg{ {Name: "value"}, {Name: "prefix"}, }, Eval: func(args map[string]any) Result { value, err := IndexFuncArg[any](args, "value") if err != nil { return Result{Error: err} } prefix, err := IndexFuncArg[any](args, "prefix") if err != nil { return Result{Error: err} } return Result{ Value: strings.HasPrefix(fmt.Sprint(value), fmt.Sprint(prefix)), } }, }, }
Functions ¶
func IndexKV ¶
IndexKV gets element key from a map, interpreting it as a path if it contains a period.
func SetDebugWriter ¶
func SetErrorVerbose ¶
func SetErrorVerbose(verbose bool)
SetErrorVerbose enables or disables verbose error reporting
Types ¶
type ArrayValue ¶
type ArrayValue struct {
// contains filtered or unexported fields
}
func (*ArrayValue) Eval ¶
func (a *ArrayValue) Eval(ctx *Ctx) Result
func (*ArrayValue) String ¶
func (a *ArrayValue) String() string
type ErrInvalidFunctionArg ¶
func (*ErrInvalidFunctionArg) Error ¶
func (e *ErrInvalidFunctionArg) Error() string
type ErrMissingFields ¶
func (ErrMissingFields) Error ¶
func (e ErrMissingFields) Error() string
type FieldValue ¶
type FieldValue string
func (FieldValue) Eval ¶
func (f FieldValue) Eval(ctx *Ctx) Result
func (FieldValue) String ¶
func (f FieldValue) String() string
type Function ¶
type Function struct {
// Args is an optional list of arguments that the function expects.
// If set, rulekit will ensure validity of the arguments and pass them as a named map to the Eval function.
Args []FunctionArg
// Eval is the function that will be called with the arguments.
// EvaluatedRule will be set by Rulekit.
Eval func(map[string]any) Result
}
type FunctionArg ¶
type FunctionArg struct {
Name string
}
type FunctionValue ¶
type FunctionValue struct {
// contains filtered or unexported fields
}
func (*FunctionValue) Eval ¶
func (f *FunctionValue) Eval(ctx *Ctx) Result
func (*FunctionValue) String ¶
func (f *FunctionValue) String() string
func (*FunctionValue) ValidateStdlibFnArgs ¶
func (f *FunctionValue) ValidateStdlibFnArgs() error
type HexString ¶
type HexString struct {
Bytes []byte
// contains filtered or unexported fields
}
HexString represents a hex-encoded string retaining the original input string
func ParseHexString ¶
type LiteralValue ¶
type LiteralValue[T any] struct { // contains filtered or unexported fields }
func (*LiteralValue[T]) Eval ¶
func (l *LiteralValue[T]) Eval(ctx *Ctx) Result
func (*LiteralValue[T]) String ¶
func (l *LiteralValue[T]) String() string
type ParseError ¶
func (*ParseError) Error ¶
func (e *ParseError) Error() string
type Result ¶
func (Result) Fail ¶
Fail returns true if the rule is ok and returns a zero value. This is usually used for boolean rules.
type Rule ¶
type ValueParseError ¶
func (ValueParseError) Error ¶
func (e ValueParseError) Error() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.
