Documentation
¶
Index ¶
- Constants
- Variables
- func AssignVectorNode(dst, src any, _ inspector.AccumulativeBuffer) (ok bool)
- func Decode(key string, ctx *Ctx) error
- func DecodeByID(id int, ctx *Ctx) error
- func DecodeFallback(key, fbKey string, ctx *Ctx) error
- func DecodeRuleset(ruleset Ruleset, ctx *Ctx) (err error)
- func Docgen(format DocgenFormat) ([]byte, error)
- func RegisterDecoder(id int, key string, tree *Tree)
- func RegisterDecoderID(id int, tree *Tree)
- func RegisterDecoderKey(key string, tree *Tree)
- func RegisterPool(key string, pool Pool) error
- func ReleaseCtx(ctx *Ctx)
- func WriteDocgen(w io.Writer, format DocgenFormat) error
- type CallbackFn
- type CallbackFnTuple
- type CondFn
- type CondFnTuple
- type CondOKFn
- type CondOKTuple
- type Ctx
- func (ctx *Ctx) AcquireBytes() []byte
- func (ctx *Ctx) AcquireFrom(pool string) (any, error)
- func (ctx *Ctx) Bufferize(p []byte) []byte
- func (ctx *Ctx) BufferizeString(s string) string
- func (ctx *Ctx) Get(path string) any
- func (ctx *Ctx) ReleaseBytes(p []byte)
- func (ctx *Ctx) Reset()
- func (ctx *Ctx) Set(key string, val any, ins inspector.Inspector)
- func (ctx *Ctx) SetStatic(key string, val any)
- func (ctx *Ctx) SetVector(key string, vec vector.Interface)
- func (ctx *Ctx) SetVectorNode(key string, node *vector.Node) error
- type CtxPool
- type Decoder
- type DocgenFormat
- type GetterFn
- type GetterFnTuple
- type Global
- type GlobalTuple
- type ModFn
- type ModFnTuple
- type Pool
- type RangeLoop
- type Ruleset
- type Tree
Constants ¶
const ( DocgenFormatMarkdown DocgenFormat = "markdown" DocgenFormatHTML = "html" DocgenFormatJSON = "json" )
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") ErrUnbalancedCtl = errors.New("unbalanced control structures found") ErrUnexpectedClose = errors.New("unexpected close bracket") ErrWrongLoopLim = errors.New("wrong count loop limit argument") ErrWrongLoopCond = errors.New("wrong loop condition operation") ErrWrongLoopOp = errors.New("wrong loop operation") ErrBreakLoop = errors.New("break loop") ErrLBreakLoop = errors.New("lazybreak loop") ErrContLoop = errors.New("continue loop") ErrSenselessCond = errors.New("comparison of two static args") ErrCondHlpNotFound = errors.New("condition helper not found") ErrUnknownPool = errors.New("unknown pool") )
Functions ¶
func AssignVectorNode ¶
func AssignVectorNode(dst, src any, _ 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 DecodeByID ¶ added in v1.1.5
DecodeByID applies decoder rules using given id.
func DecodeFallback ¶ added in v1.1.5
DecodeFallback applies decoder rules using one of keys: key or fallback key.
Using this func you can handle cases when some objects have custom decoders and all other should use default decoders. Example: decoder registry: * decoderUser * decoderUser-15 user object with id 15 Call of decoder.DecoderFallback("decUser-15", "decUser", ctx) will take decoder decUser-15 from registry. In other case, for user #4: call of decoder.DecoderFallback("decUser-4", "decUser", ctx) will take default decoder decUser from registry.
func DecodeRuleset ¶
DecodeRuleset applies decoder ruleset without using id.
func Docgen ¶ added in v1.1.4
func Docgen(format DocgenFormat) ([]byte, error)
func RegisterDecoder ¶
RegisterDecoder saves decoder by ID and key in the registry.
You may use to access to the decoder both ID or key. This function can be used in any time to register new decoders or overwrite existing to provide dynamics.
func RegisterDecoderID ¶ added in v1.1.5
RegisterDecoderID saves decoder using only ID.
See RegisterDecoder().
func RegisterDecoderKey ¶ added in v1.1.5
RegisterDecoderKey saves decoder using only key.
See RegisterDecoder().
func RegisterPool ¶ added in v1.1.0
RegisterPool adds new internal pool to the registry by given key.
func WriteDocgen ¶ added in v1.1.4
func WriteDocgen(w io.Writer, format DocgenFormat) error
Types ¶
type CallbackFn ¶
CallbackFn represents the signature of callback function.
args contains list of all arguments you passed in decoder node.
func GetCallbackFn ¶
func GetCallbackFn(name string) CallbackFn
GetCallbackFn returns callback function from the registry.
type CallbackFnTuple ¶ added in v1.1.4
type CallbackFnTuple struct {
// contains filtered or unexported fields
}
func RegisterCallbackFn ¶
func RegisterCallbackFn(name, alias string, cb CallbackFn) *CallbackFnTuple
RegisterCallbackFn registers new callback to the registry.
func RegisterCallbackFnNS ¶ added in v1.1.0
func RegisterCallbackFnNS(namespace, name, alias string, cb CallbackFn) *CallbackFnTuple
RegisterCallbackFnNS registers new callback in given namespace.
func (*CallbackFnTuple) WithDescription ¶ added in v1.1.4
func (t *CallbackFnTuple) WithDescription(desc string) *docgen
func (*CallbackFnTuple) WithExample ¶ added in v1.1.4
func (t *CallbackFnTuple) WithExample(example string) *docgen
func (*CallbackFnTuple) WithNote ¶ added in v1.1.4
func (t *CallbackFnTuple) WithNote(note string) *docgen
type CondFnTuple ¶ added in v1.1.5
type CondFnTuple struct {
// contains filtered or unexported fields
}
func RegisterCondFn ¶ added in v1.1.5
func RegisterCondFn(name string, cond CondFn) *CondFnTuple
RegisterCondFn registers new condition helper.
func RegisterCondFnNS ¶ added in v1.1.5
func RegisterCondFnNS(namespace, name string, cond CondFn) *CondFnTuple
RegisterCondFnNS registers new condition helper in given namespace.
func (*CondFnTuple) WithDescription ¶ added in v1.1.5
func (t *CondFnTuple) WithDescription(desc string) *docgen
func (*CondFnTuple) WithExample ¶ added in v1.1.5
func (t *CondFnTuple) WithExample(example string) *docgen
type CondOKFn ¶ added in v1.1.5
CondOKFn describes helper func signature.
func GetCondOKFn ¶ added in v1.1.5
GetCondOKFn returns condition-OK helper from the registry.
type CondOKTuple ¶ added in v1.1.5
type CondOKTuple struct {
// contains filtered or unexported fields
}
func RegisterCondOKFn ¶ added in v1.1.5
func RegisterCondOKFn(name string, cond CondOKFn) *CondOKTuple
RegisterCondOKFn registers new condition-OK helper.
func RegisterCondOKFnNS ¶ added in v1.1.5
func RegisterCondOKFnNS(namespace, name string, cond CondOKFn) *CondOKTuple
RegisterCondOKFnNS registers new condition-OK helper in given namespace.
func (*CondOKTuple) WithDescription ¶ added in v1.1.5
func (t *CondOKTuple) WithDescription(desc string) *docgen
func (*CondOKTuple) WithExample ¶ added in v1.1.5
func (t *CondOKTuple) WithExample(example string) *docgen
type Ctx ¶
type Ctx struct {
BufT time.Time
// External buffers to use in modifier and condition helpers.
BufAcc bytebuf.Accumulative
// todo remove as unused later
Buf, Buf1, Buf2 bytebuf.Chain
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) AcquireFrom ¶ added in v1.1.0
AcquireFrom receives new variable from given pool and register it to return batch after finish decoder processing.
func (*Ctx) BufferizeString ¶ added in v1.0.2
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 ¶
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 DocgenFormat ¶ added in v1.1.4
type DocgenFormat string
type GetterFn ¶
GetterFn represents signature of getter callback function.
args contains list of all arguments you passed in decoder node.
func GetGetterFn ¶
GetGetterFn returns getter callback function from the registry.
type GetterFnTuple ¶ added in v1.1.4
type GetterFnTuple struct {
// contains filtered or unexported fields
}
func RegisterGetterFn ¶
func RegisterGetterFn(name, alias string, cb GetterFn) *GetterFnTuple
RegisterGetterFn registers new getter callback to the registry.
func RegisterGetterFnNS ¶ added in v1.1.0
func RegisterGetterFnNS(namespace, name, alias string, cb GetterFn) *GetterFnTuple
RegisterGetterFnNS registers new getter callback in given namespace.
func (*GetterFnTuple) WithDescription ¶ added in v1.1.4
func (t *GetterFnTuple) WithDescription(desc string) *docgen
func (*GetterFnTuple) WithExample ¶ added in v1.1.4
func (t *GetterFnTuple) WithExample(example string) *docgen
func (*GetterFnTuple) WithNote ¶ added in v1.1.4
func (t *GetterFnTuple) WithNote(note string) *docgen
type GlobalTuple ¶ added in v1.1.5
type GlobalTuple struct {
// contains filtered or unexported fields
}
func RegisterGlobal ¶ added in v1.1.5
func RegisterGlobal(name, alias string, val Global) *GlobalTuple
RegisterGlobal registers new global variable.
Caution! Globals registered after template parsing will take no effect.
func RegisterGlobalNS ¶ added in v1.1.5
func RegisterGlobalNS(namespace, name, alias string, val Global) *GlobalTuple
RegisterGlobalNS registers new global variable in given namespace.
func (*GlobalTuple) WithDescription ¶ added in v1.1.5
func (t *GlobalTuple) WithDescription(desc string) *docgen
func (*GlobalTuple) WithExample ¶ added in v1.1.5
func (t *GlobalTuple) WithExample(example string) *docgen
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 ModFnTuple ¶ added in v1.1.4
type ModFnTuple struct {
// contains filtered or unexported fields
}
func RegisterModFn ¶
func RegisterModFn(name, alias string, mod ModFn) *ModFnTuple
RegisterModFn registers new modifier function.
func RegisterModFnNS ¶ added in v1.1.0
func RegisterModFnNS(namespace, name, alias string, mod ModFn) *ModFnTuple
RegisterModFnNS registers new modifier function in given namespace.
func (*ModFnTuple) WithDescription ¶ added in v1.1.4
func (t *ModFnTuple) WithDescription(desc string) *docgen
func (*ModFnTuple) WithExample ¶ added in v1.1.4
func (t *ModFnTuple) WithExample(example string) *docgen
type Pool ¶ added in v1.1.0
type Pool interface {
Get() any
Put(any)
// Reset cleanups data before putting to the pool.
Reset(any)
}
Pool represents internal pool. In addition to native sync.Pool requires Reset() method.
type RangeLoop ¶ added in v1.1.5
type RangeLoop struct {
// contains filtered or unexported fields
}
RangeLoop is a object that injects to inspector to perform range loop execution.
func NewRangeLoop ¶ added in v1.1.5
NewRangeLoop makes new RL.
func (*RangeLoop) RequireKey ¶ added in v1.1.5
RequireKey checks if node requires a key to store in the context.
func (*RangeLoop) Reset ¶ added in v1.1.5
func (rl *RangeLoop) Reset()
Reset clears all data in the list of RL.
type Tree ¶ added in v1.1.5
type Tree struct {
// contains filtered or unexported fields
}
Tree represents list of nodes.
func (*Tree) HumanReadable ¶ added in v1.1.5
HumanReadable builds human-readable view of the nodes list.