Documentation ¶
Index ¶
- func DeepCopyObject(from interface{}) (interface{}, error)
- func Fetch(s string, opt Options) ([]byte, error)
- func FromJSON(o interface{}) (interface{}, error)
- func FromMap(m map[string]interface{}, raw interface{}) error
- func IndexOf(srch interface{}, array interface{}, strictOptional ...bool) int
- func QueryObject(exp string, target interface{}) (interface{}, error)
- func SplitLines(o interface{}) ([]string, error)
- func ToJSON(o interface{}) (string, error)
- func ToJSONFormat(prefix, indent string, o interface{}) (string, error)
- func ToMap(raw interface{}) (map[string]interface{}, error)
- func UnixTime() interface{}
- type Context
- type Function
- type FunctionExporter
- type Options
- type Template
- func (t *Template) AddDef(name string, val interface{}, doc ...string) *Template
- func (t *Template) AddFunc(name string, f interface{}) *Template
- func (t *Template) DefaultFuncs() []Function
- func (t *Template) Dot() interface{}
- func (t *Template) Execute(output io.Writer, context interface{}) error
- func (t *Template) Funcs() []Function
- func (t *Template) Global(name string, value interface{})
- func (t *Template) Ref(name string) interface{}
- func (t *Template) Render(context interface{}) (string, error)
- func (t *Template) SetOptions(opt Options) *Template
- func (t *Template) Validate() (*Template, error)
- type Void
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeepCopyObject ¶ added in v0.3.1
func DeepCopyObject(from interface{}) (interface{}, error)
DeepCopyObject makes a deep copy of the argument, using encoding/gob encode/decode.
func Fetch ¶ added in v0.3.1
Fetch fetchs content from the given URL string. Supported schemes are http:// https:// file:// unix://
func FromJSON ¶
func FromJSON(o interface{}) (interface{}, error)
FromJSON decode the input JSON encoded as string or byte slice into a map.
func IndexOf ¶ added in v0.3.1
IndexOf returns the index of search in array. -1 if not found or array is not iterable. An optional true will turn on strict type check while by default string representations are used to compare values.
func QueryObject ¶
QueryObject applies a JMESPath query specified by the expression, against the target object.
func SplitLines ¶
SplitLines splits the input into a string slice.
func ToJSONFormat ¶ added in v0.3.1
ToJSONFormat encodes the input struct into a JSON string with format prefix, and indent.
Types ¶
type Context ¶ added in v0.3.0
type Context interface { // Funcs returns a list of special template functions of the form func(template.Context, arg1, arg2) interface{} Funcs() []Function }
Context is a marker interface for a user-defined struct that is passed into the template engine (as context) and accessible in the exported template functions. Template functions can have the signature func(template.Context, arg1, arg2 ...) (string, error) and when functions like this are registered, the template engine will dynamically create and export a function of the form func(arg1, arg2...) (string, error) where the context instance becomes an out-of-band struct that can be mutated by functions. This in essence allows structured data as output of the template, in addition to a string from evaluating the template.
type Function ¶ added in v0.3.0
type Function struct { // Name is the function name to bind in the template Name string // Description provides help for the function Description []string `json:",omitempty"` // Func is the reference to the actual function Func interface{} `json:"-"` // Function is the signature of the function Function string // Usage shows how to use it Usage string `json:",omitempty"` }
Function contains the description of an exported template function
func UpdateDocumentation ¶ added in v0.3.1
UpdateDocumentation uses reflection to generate documentation on usage and function signature.
type FunctionExporter ¶ added in v0.3.1
type FunctionExporter interface { // Funcs returns a list of special template functions of the form func(template.Context, arg1, arg2) interface{} Funcs() []Function }
FunctionExporter is implemented by any plugins wishing to show help on the function it exports.
type Options ¶
type Options struct { // SocketDir is the directory for locating the socket file for // a template URL of the form unix://socket_file/path/to/resource SocketDir string }
Options contains parameters for customizing the behavior of the engine
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is the templating engine
func NewTemplate ¶
NewTemplate fetches the content at the url and returns a template. If the string begins with str:// as scheme, then the rest of the string is interpreted as the body of the template.
func NewTemplateFromBytes ¶
NewTemplateFromBytes builds the template from buffer with a contextURL which is used to deduce absolute path of any 'included' templates e.g. {{ include "./another.tpl" . }}
func (*Template) AddDef ¶ added in v0.3.1
AddDef is equivalent to a {{ def "key" value "description" }} in defining a variable with a default value. The value is accessible via a {{ ref "key" }} in the template.
func (*Template) DefaultFuncs ¶
DefaultFuncs returns a list of default functions for binding in the template
func (*Template) Dot ¶ added in v0.3.1
func (t *Template) Dot() interface{}
Dot returns the '.' in this template.
func (*Template) Funcs ¶ added in v0.3.1
Funcs returns a list of registered functions used by the template when it rendered the view.
func (*Template) Global ¶ added in v0.3.1
Global sets the a key, value in the context of this template. It is visible to all the 'included' and 'sourced' templates by the calling template.
func (*Template) Ref ¶ added in v0.3.1
Ref returns the value keyed by name in the context of this template. See 'ref' template function.
func (*Template) SetOptions ¶
SetOptions sets the runtime flags for the engine