Documentation ¶
Index ¶
- Constants
- Variables
- func AssignVectorNode(dst, src any, _ inspector.AccumulativeBuffer) (ok bool)
- func Decode(id string, ctx *Ctx) error
- func DecodeRuleset(ruleset Ruleset, ctx *Ctx) (err error)
- func Docgen(format DocgenFormat) ([]byte, error)
- func RegisterDecoder(id string, rules Ruleset)
- func RegisterPool(key string, pool Pool) error
- func ReleaseCtx(ctx *Ctx)
- func WriteDocgen(w io.Writer, format DocgenFormat) error
- type CallbackFn
- type CallbackFnTuple
- 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 ModFn
- type ModFnTuple
- type Pool
- type Ruleset
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") 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 DecodeRuleset ¶
DecodeRuleset applies decoder ruleset without using id.
func Docgen ¶ added in v1.1.4
func Docgen(format DocgenFormat) ([]byte, error)
func RegisterDecoder ¶
RegisterDecoder registers decoder ruleset in the registry.
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 rule.
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 Ctx ¶
type Ctx struct { // 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 template 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 ¶
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 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 rule.
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 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.