Documentation
¶
Index ¶
- func ApplyTools(v any, tc ToolContext, tools ...*Tool) gomerr.Gomerr
- func Preprocess(v any, tools ...*Tool) gomerr.Gomerr
- func RegisterToolFunction(name string, function ToolFunction) gomerr.Gomerr
- func RegisterToolFunctions(functions map[string]ToolFunction) gomerr.Gomerr
- func RegisterValueConstants(constants map[string]any)
- func ScopeAlias(alias, scope string)
- func ScopeAliases(aliasToScope map[string]string)
- func SetNowToolFunctionPrecision(precision time.Duration)
- func ValueFromStruct(sv reflect.Value, fv reflect.Value, source string) (any, gomerr.Gomerr)
- type Applier
- type ApplierProvider
- type DirectiveProvider
- type MissingDirectiveHandler
- type NoApplier
- type StructApplier
- type StructTagDirectiveProvider
- type Tool
- type ToolContext
- func (tc ToolContext) Delete(key string) any
- func (tc ToolContext) Descend(location string, createIntermediates bool) (ToolContext, bool)
- func (tc ToolContext) Get(key string) any
- func (tc ToolContext) Lookup(key string) (any, bool)
- func (tc ToolContext) LookupNested(key string) (ToolContext, bool)
- func (tc ToolContext) Put(key string, value any) any
- func (tc ToolContext) PutScope(scope string) string
- func (tc ToolContext) Scope() string
- func (tc ToolContext) With(key string, value any) ToolContext
- type ToolFunction
- type ValueApplier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyTools ¶
func ApplyTools(v any, tc ToolContext, tools ...*Tool) gomerr.Gomerr
func RegisterToolFunction ¶
func RegisterToolFunction(name string, function ToolFunction) gomerr.Gomerr
func RegisterToolFunctions ¶
func RegisterToolFunctions(functions map[string]ToolFunction) gomerr.Gomerr
func RegisterValueConstants ¶
func ScopeAlias ¶
func ScopeAlias(alias, scope string)
ScopeAlias allows the caller to specify an alternative value to use when defining scoped configuration from the scope used during the application of a tool. Aliases need to be defined before PrepareTool() is called.
func ScopeAliases ¶
Types ¶
type Applier ¶
type Applier interface {
Apply(structValue reflect.Value, fieldValue reflect.Value, toolContext ToolContext) gomerr.Gomerr
}
func Composite ¶
func Composite(directive string, tool *Tool, st reflect.Type, sf reflect.StructField) (Applier, gomerr.Gomerr)
Composite checks for a composition directive (one of 'if', '?', '&' or '!') and if found, creates a composed Applier from the directive. If there isn't a composition directive, this returns nil for both Applier and gomerr.Gomerr. TODO:p2 this should perhaps be a default intermediary similar to how the scope applier can be
type ApplierProvider ¶
type DirectiveProvider ¶
type DirectiveProvider interface {
Get(structField reflect.StructField) (string, bool)
}
type MissingDirectiveHandler ¶ added in v0.3.0
type MissingDirectiveHandler interface {
DefaultDirective() string
}
MissingDirectiveHandler can be implemented by an ApplierProvider to indicate that fields without the struct tag should still be processed. The returned string is used as the default directive.
type StructApplier ¶
type StructApplier struct {
Source string
}
func (StructApplier) Apply ¶
func (a StructApplier) Apply(sv reflect.Value, fv reflect.Value, _ ToolContext) gomerr.Gomerr
type StructTagDirectiveProvider ¶
type StructTagDirectiveProvider struct {
TagKey string
}
func (StructTagDirectiveProvider) Get ¶
func (s StructTagDirectiveProvider) Get(structField reflect.StructField) (string, bool)
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool contains references to some behavior that can be applied to structs present in an application.
func NewTool ¶
func NewTool(toolType string, ap ApplierProvider, dp DirectiveProvider) *Tool
func (*Tool) ApplierProvider ¶
func (t *Tool) ApplierProvider() ApplierProvider
type ToolContext ¶
func EnsureContext ¶
func EnsureContext(tcs ...ToolContext) ToolContext
func ToolContextWithScope ¶
func ToolContextWithScope(scope string) ToolContext
func (ToolContext) Delete ¶ added in v0.2.0
func (tc ToolContext) Delete(key string) any
func (ToolContext) Descend ¶
func (tc ToolContext) Descend(location string, createIntermediates bool) (ToolContext, bool)
func (ToolContext) Get ¶
func (tc ToolContext) Get(key string) any
func (ToolContext) LookupNested ¶
func (tc ToolContext) LookupNested(key string) (ToolContext, bool)
func (ToolContext) PutScope ¶
func (tc ToolContext) PutScope(scope string) string
func (ToolContext) Scope ¶
func (tc ToolContext) Scope() string
func (ToolContext) With ¶ added in v0.2.0
func (tc ToolContext) With(key string, value any) ToolContext
type ToolFunction ¶
type ToolFunction func(structValue reflect.Value, fieldValue reflect.Value, toolContext ToolContext) (output any, ge gomerr.Gomerr)
func GetToolFunction ¶
func GetToolFunction(name string) ToolFunction
func (ToolFunction) Apply ¶
func (f ToolFunction) Apply(sv reflect.Value, fv reflect.Value, tc ToolContext) gomerr.Gomerr
type ValueApplier ¶
type ValueApplier struct {
StaticValue string
}
func (ValueApplier) Apply ¶
func (a ValueApplier) Apply(_ reflect.Value, fv reflect.Value, _ ToolContext) gomerr.Gomerr