Documentation
¶
Index ¶
- Constants
- func DeepCopyObject(from interface{}) (interface{}, error)
- func Dir() string
- func Escape(source []byte) []byte
- func Fetch(s string, opt Options) ([]byte, error)
- func FromHCL(o interface{}) (interface{}, error)
- func FromINI(v string) (map[string]interface{}, error)
- func FromJSON(o interface{}) (interface{}, error)
- func FromMap(m map[string]interface{}, raw interface{}) error
- func FromYAML(o interface{}) (interface{}, error)
- func GetURL(root, rel string) (*url.URL, error)
- func IndexOf(srch interface{}, array interface{}, strictOptional ...bool) int
- func QueryObject(exp string, target interface{}) (interface{}, error)
- func Setup() 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 ToYAML(o interface{}) (string, error)
- func Unescape(source []byte) []byte
- func UnixTime() interface{}
- func ValidURL(s string) string
- type Context
- type Function
- type FunctionExporter
- type Options
- type Template
- func (t *Template) AddFunc(name string, f interface{}) *Template
- func (t *Template) DefaultFuncs() []Function
- func (t *Template) DeferVar(name string) string
- func (t *Template) Dot() interface{}
- func (t *Template) Execute(output io.Writer, context interface{}) error
- func (t *Template) Fetch(p string, opt ...interface{}) (string, error)
- func (t *Template) Funcs() []Function
- func (t *Template) Global(name string, value interface{}) *Template
- func (t *Template) Globals() (map[string]interface{}, error)
- func (t *Template) Include(p string, opt ...interface{}) (string, error)
- func (t *Template) Options() Options
- func (t *Template) Raw(p string, opt ...interface{}) ([]byte, error)
- func (t *Template) Ref(name string) interface{}
- func (t *Template) RemoveFunc(name ...string) *Template
- func (t *Template) Render(context interface{}) (string, error)
- func (t *Template) SetOptions(opt Options) *Template
- func (t *Template) Source(p string, opt ...interface{}) (string, error)
- func (t *Template) Validate() (*Template, error)
- func (t *Template) Var(name string, optional ...interface{}) interface{}
- func (t *Template) WithFunctions(functions func() []Function) *Template
- type Void
Constants ¶
const CacheDirEnvVar = "INFRAKIT_PLAYBOOKS_CACHE"
CacheDirEnvVar is the environment variable used to set the cache of the playbooks
Variables ¶
This section is empty.
Functions ¶
func DeepCopyObject ¶
func DeepCopyObject(from interface{}) (interface{}, error)
DeepCopyObject makes a deep copy of the argument, using encoding/gob encode/decode.
func Dir ¶
func Dir() string
Dir returns the directory to use for playbooks caching which can be customize via environment variable
func Fetch ¶
Fetch fetchs content from the given URL string. Supported schemes are http:// https:// file:// unix://
func FromHCL ¶
func FromHCL(o interface{}) (interface{}, error)
FromHCL decode the input HCL encoded as string or byte slice into a Go value
func FromJSON ¶
func FromJSON(o interface{}) (interface{}, error)
FromJSON decode the input JSON encoded as string or byte slice into a Go value.
func FromYAML ¶
func FromYAML(o interface{}) (interface{}, error)
FromYAML decode the input YAML encoded as string or byte slice into a Go value.
func GetURL ¶
GetURL returns a url string of the base and a relative path. e.g. http://host/foo/bar/baz, ./boo.tpl gives http://host/foo/bar/boo.tpl
func IndexOf ¶
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 Setup ¶
func Setup() error
Setup sets up the necessary environment for running this module -- ie make sure cache directory exists, etc.
func SplitLines ¶
SplitLines splits the input into a string slice.
func ToJSONFormat ¶
ToJSONFormat encodes the input struct into a JSON string with format prefix, and indent.
Types ¶
type Context ¶
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 ¶
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 ¶
UpdateDocumentation uses reflection to generate documentation on usage and function signature.
type FunctionExporter ¶
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 { // DelimLeft is the left delimiter, default is {{ DelimLeft string // DelimRight is the right delimiter, default is }} DelimRight string // CustomizeFetch allows setting of http request header, etc. during fetch CustomizeFetch func(*http.Request) `json:"-" yaml:"-"` // Stderr is a function that returns stream to use for stderr Stderr func() io.Writer `json:"-" yaml:"-"` // MultiPass can affect the behavior of some functions like `var` where // evaluation of the function return different results based on whether the // template is meant to be evaluated in multiple passes. MultiPass bool // CacheDir is the location of the cache CacheDir 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 NewFromTemplate ¶
NewFromTemplate creates a new template from existing, without any fetches (hence network calls)
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) DefaultFuncs ¶
DefaultFuncs returns a list of default functions for binding in the template
func (*Template) DeferVar ¶
DeferVar returns a template expression for a var that isn't resolved at this iteration
func (*Template) Funcs ¶
Funcs returns a list of registered functions used by the template when it rendered the view.
func (*Template) Global ¶
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) RemoveFunc ¶
RemoveFunc remove the functions
func (*Template) SetOptions ¶
SetOptions sets the runtime flags for the engine
func (*Template) Var ¶
Var implements the var function. It's a combination of global and ref Note that the behavior of the var function depends on whether the template is used in multiple passes where some var cannot be resolved to values in the first pass. In this case, if the MultiplePass flag is set, the var function will just echo back the same template expression in case of no value.
func (*Template) WithFunctions ¶
WithFunctions allows client code to extend the template by adding its own functions.