template

package
v0.0.0-...-21d6f6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2016 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingTemplateFunc = errors.New("err-no-template-func")
	ErrBadTemplateFunc     = errors.New("err-bad-template-func")
	ErrNotImplemented      = errors.New("err-not-implemented")
)
View Source
var (
	NullTemplate string = ""
	NullContent  string = ""
)
View Source
var (
	TemplateDataContextKey templateDataContextKey = 1
)
View Source
var TimeoutContextKey timeoutContextKey = 1

Functions

func Apply

func Apply(tmpl []byte, data interface{}, funcs ...template.FuncMap) ([]byte, error)

Generic Apply template. This is simple convenince wrapper that generates a hash key for the template name based on the template content itself.

func Apply2

func Apply2(tmpl []byte, data interface{}, funcs ...template.FuncMap) ([]byte, error)

Two-pass apply. This supports the notion of a define template block where the content is in YAML. The content in YAML is then parsed and in the second pass any template expressions that calls the function {{my <var>}} will access the values in the define blocks.

For example:

{{define "app"}} version: 1.2 image: repo build: 1234 {{end}}

{{define "host"}} label: appserver name: myhost {{end}}

{
   "image" : "repo/myapp:{{my app.version}}-{{my app.build}}",
   "host" : "{{my host.name}}"
}

Will turn into:

{
   "image" : "repo/myapp:1.2-1234",
   "host" : "myhost"
}

func ContentInline

func ContentInline(ctx context.Context) interface{}

Fetch the url and write content inline ex) {{ inline "http://file/here" }}

func ContentToFile

func ContentToFile(ctx context.Context) interface{}

func ContextGetTemplateData

func ContextGetTemplateData(ctx context.Context) interface{}

func ContextGetTimeout

func ContextGetTimeout(ctx context.Context) time.Duration

func ContextPutTemplateData

func ContextPutTemplateData(ctx context.Context, data interface{}) context.Context

func ContextPutTimeout

func ContextPutTimeout(ctx context.Context, duration time.Duration) context.Context

func DefaultFuncMap

func DefaultFuncMap(ctx context.Context) template.FuncMap

func Execute

func Execute(ctx context.Context, uri string, funcs ...template.FuncMap) ([]byte, error)

Execute a template at the given uri/url. The data to be applied to the template should be placed in the context via the ContextPutTemplateData() function.

func ExecuteShell

func ExecuteShell(ctx context.Context) interface{}

This will bock until the shell executes to completion. The output to stdout is buffered internally and available for reading in the returned io.Reader. This function will block until all the data to stdout has been captured.

func GetEnvironmentVariable

func GetEnvironmentVariable(ctx context.Context) interface{}

func GetKeyForTemplate

func GetKeyForTemplate(tmpl []byte) string

func IsUrl

func IsUrl(s string) bool

func MergeFuncMaps

func MergeFuncMaps(a, b template.FuncMap) template.FuncMap

func ParseHost

func ParseHost(ctx context.Context) interface{}

TODO - Add support for interpreting URL string so we can pull from zk or http

func ParseHostPort

func ParseHostPort(ctx context.Context) interface{}

TODO - Add support for interpreting URL string so we can pull from zk or http

func ParsePort

func ParsePort(ctx context.Context) interface{}

TODO - Add support for interpreting URL string so we can pull from zk or http

func RegisterFunc

func RegisterFunc(name string, generator func(context.Context) interface{})

Types

type NotSupported

type NotSupported struct {
	Protocol string
}

func (*NotSupported) Error

func (this *NotSupported) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL