Documentation
¶
Index ¶
- Variables
- func AssignVectorNode(dst, src interface{}, _ inspector.AccumulativeBuffer) (ok bool)
- func Decode(id string, ctx *Ctx) error
- func DecodeRuleset(ruleset Ruleset, ctx *Ctx) (err error)
- func RegisterCallbackFn(name, alias string, cb CallbackFn)
- func RegisterDecoder(id string, rules Ruleset)
- func RegisterGetterFn(name, alias string, cb GetterFn)
- func RegisterModFn(name, alias string, mod ModFn)
- func ReleaseCtx(ctx *Ctx)
- type CallbackFn
- type Ctx
- func (ctx *Ctx) AcquireBytes() []byte
- func (ctx *Ctx) Get(path string) interface{}
- func (ctx *Ctx) ReleaseBytes(p []byte)
- func (ctx *Ctx) Reset()
- func (ctx *Ctx) Set(key string, val interface{}, ins inspector.Inspector)
- func (ctx *Ctx) SetStatic(key string, val interface{})
- func (ctx *Ctx) SetVector(key string, data []byte, typ VectorType) (vec vector.Interface, err error)
- func (ctx *Ctx) SetVectorNode(key string, node *vector.Node) error
- type CtxPool
- type Decoder
- type GetterFn
- type ModFn
- type Ruleset
- type VectorType
Constants ¶
This section is empty.
Variables ¶
var ( ErrDecoderNotFound = errors.New("decoder not found") ErrEmptyNode = errors.New("provided node is empty") ErrModNoArgs = errors.New("empty arguments list") ErrModPoorArgs = errors.New("arguments list in modifier is too small") ErrCbPoorArgs = errors.New("arguments list in callback is too small") ErrGetterPoorArgs = errors.New("arguments list in getter callback is too small") )
Functions ¶
func AssignVectorNode ¶
func AssignVectorNode(dst, src interface{}, _ inspector.AccumulativeBuffer) (ok bool)
AssignVectorNode implements assign callback to convert vector.Node to destination with arbitrary type.
func Decode ¶
Decode applies decoder rules using given id.
ctx should contain all variables mentioned in the decoder's body.
func DecodeRuleset ¶
DecodeRuleset applies decoder ruleset without using id.
func RegisterCallbackFn ¶
func RegisterCallbackFn(name, alias string, cb CallbackFn)
RegisterCallbackFn registers new callback to the registry.
func RegisterDecoder ¶
RegisterDecoder registers decoder ruleset in the registry.
func RegisterGetterFn ¶
RegisterGetterFn registers new getter callback to the registry.
func RegisterModFn ¶
RegisterModFn registers new modifier function.
Types ¶
type CallbackFn ¶
CallbackFn represents the signature of callback function.
args contains list of all arguments you passed in decoder rule.
func GetCallbackFn ¶
func GetCallbackFn(name string) *CallbackFn
GetCallbackFn returns callback function from the registry.
type Ctx ¶
type Ctx struct { // External buffers to use in modifier and condition helpers. BufAcc bytebuf.AccumulativeBuf // todo remove as unused later Buf, Buf1, Buf2 bytebuf.ChainBuf Err error // contains filtered or unexported fields }
Ctx represents decoder context object.
Contains list of variables that can be used as source or destination.
func (*Ctx) AcquireBytes ¶
AcquireBytes returns accumulative buffer.
func (*Ctx) Get ¶
Get arbitrary value from the context by path.
See Ctx.get(). Path syntax: <ctxVrName>[.<Field>[.<NestedField0>[....<NestedFieldN>]]] Examples: * user.Bio.Birthday * staticVar
func (*Ctx) ReleaseBytes ¶
ReleaseBytes updates accumulative buffer with p.
func (*Ctx) Set ¶
Set the variable to context. Inspector ins should be corresponded to variable val.
type CtxPool ¶
type CtxPool struct {
// contains filtered or unexported fields
}
CtxPool represents context pool.
var ( // CP is a default instance of context pool. // You may use it directly as decoder.CP.Get()/Put() or using functions AcquireCtx()/ReleaseCtx(). CP CtxPool )
type Decoder ¶
type Decoder struct { Id string // contains filtered or unexported fields }
Decoder represents main decoder object. Decoder contains only parsed ruleset. All temporary and intermediate data should be store in context logic to make using of decoders thread-safe.
type GetterFn ¶
GetterFn represents signature of getter callback function.
args contains list of all arguments you passed in decoder rule.
func GetGetterFn ¶
GetGetterFn returns getter callback function from the registry.
type ModFn ¶
ModFn represents signature of the modifier functions.
Arguments description: * ctx provides access to additional variables and various buffers to reduce allocations. * buf is a storage for final result after finishing modifier work. * val is a left side variable that preceded to call of modifier func, example: {%= val|mod(...) %} * args is a list of all arguments listed on modifier call.
type Ruleset ¶
type Ruleset []rule
Ruleset represents list of rules.
func (*Ruleset) HumanReadable ¶
HumanReadable builds human-readable view of the rules list.
type VectorType ¶
type VectorType int
const ( VectorJSON VectorType = iota VectorURL VectorXML VectorYAML VectorsSupported = 4 )