template

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2019 License: MIT Imports: 29 Imported by: 3

README

template

Template is a thin wrapper on text/template, the golang templating engine. The primary usecase for the utility is to dynamically modify config templates.

Usage

Typical usage is to read a file and apply a couple variables.

Example Template (ingress.yml.template):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ .Var "service" }}
  ref: {{ .Env "CURRENT_REF" }}

If we then run the following:

> CURRENT_REF="abcdef" template -f ingress.yml.template --var service="my service"

template will then print to the screen the updated template:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my service
  ref: abcdef

You can alternately read from stdin by omitting the -f flag.

Commandline Flag Reference

-f <TEMPLATE PATH>

The -f flag specifies an input file. If in the form -f - template will read the file from stdin.

-i <TEMPLATE PATH>

The -i flag specifies an addition template file referencable in the master template.

-vars <VARS PATH[.json|(.yml|.yaml|*)]>

The -vars flag specifies an input file with variable definitions. If the filename is .json it will be unmarshalled as json, otherwise it will be unmarshalled as yaml.

-var <KEY>=<VALUE>

The -var flag specifies a variable for the template.

-o <OUTPUT PATH>

The -o flag specifies an output path. If not present, output will be piped to stdout.

-delims "<LEFT DELIMITER>,<RIGHT DELIMITER>

The -delims flag specifies the left and right delimiters for template action, defaults to {{,}}.

Template Viewmodel Function Reference

The template view model (the state passed to the template) contains any variables passed into the template, and environment variables captured from the environment.

.Env

Env will return an environment variable. It takes the environment variable name as the first parameter. It can take a default value as a second parameter. If no default is specified, and the environment variable is not present, this will cause an error.

{{ .Env "<var name>" }}

With a default:

{{ .Env "<var name>" "<default value>" }}
.Var

Var will return a variable as set by the commandline. It takes the variable name as the first parameter. It can take a default value as a second parameter. If no default is specified, and the variable is not present, this will cause an error.

{{ .Var "<var name>" }}

With a default:

{{ .Var "<var name>" <default value> }}

Note: Var differs from Env in that var values can be any type, not just strings.

Template Helper Function Reference

In addition to functions found on the template viewmodel, there is a large suite of global functions you can invoke from your templates.

file

File will return the contents of a given file and inline those contents into the config. Note; the contents of this file will not be processed by the template interpreter, they will appear in the final output as they did on disk.

{{ file "<file path>" }}
file_exists

File will return the contents of a given file and inline those contents into the config. Note; the contents of this file will not be processed by the template interpreter, they will appear in the final output as they did on disk.

{{ if file_exists "<file path>" }}
yep
{{else}}
nope
{{end}}

text/template Reference

More information about the text/template template language can be found here: text template

Documentation

Overview

Package template implements helpers ontop of the stdlib `text/template`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewVarsFromPath added in v0.3.0

func NewVarsFromPath(path string) (map[string]interface{}, error)

NewVarsFromPath returns a new vars file from a given path.

Types

type Template

type Template struct {
	Viewmodel
	// contains filtered or unexported fields
}

Template is a wrapper for html.Template.

func New

func New() *Template

New creates a new template.

func NewFromFile

func NewFromFile(filepath string) (*Template, error)

NewFromFile creates a new template from a file.

func (*Template) Body

func (t *Template) Body() string

Body returns the template body.

func (*Template) MustProcessString added in v0.3.2

func (t *Template) MustProcessString() string

MustProcessString is a helper to process a template as a string and panic on error.

func (*Template) Name

func (t *Template) Name() string

Name returns the template name if set, or if not set, just "template" as a constant.

func (*Template) Process

func (t *Template) Process(dst io.Writer) error

Process processes the template.

func (*Template) ProcessString added in v0.3.2

func (t *Template) ProcessString() (string, error)

ProcessString is a helper to process the template as a string.

func (*Template) SetVar

func (t *Template) SetVar(key string, value interface{})

SetVar sets a var in the template.

func (*Template) SetVarsFromFile added in v0.3.0

func (t *Template) SetVarsFromFile(path string) error

SetVarsFromFile reads vars from a file and merges them with the current variables set.

func (*Template) ViewFuncs

func (t *Template) ViewFuncs() texttemplate.FuncMap

ViewFuncs returns the view funcs.

func (*Template) WithBody

func (t *Template) WithBody(body string) *Template

WithBody sets the template body and returns a reference to the template object.

func (*Template) WithDelims

func (t *Template) WithDelims(left, right string) *Template

WithDelims sets the template action delimiters, treating empty string as default delimiter.

func (*Template) WithEnvVars added in v0.3.0

func (t *Template) WithEnvVars(envVars env.Vars) *Template

WithEnvVars sets the environment variables.

func (*Template) WithInclude

func (t *Template) WithInclude(body string) *Template

WithInclude includes a (sub) template into the rendering assets.

func (*Template) WithName

func (t *Template) WithName(name string) *Template

WithName sets the template name.

func (*Template) WithVar

func (t *Template) WithVar(key string, value interface{}) *Template

WithVar sets a variable and returns a reference to the template object.

func (*Template) WithVars

func (t *Template) WithVars(vars Vars) *Template

WithVars reads a map of variables into the template.

type Vars

type Vars = map[string]interface{}

Vars is a soft alias to map[string]interface{}.

func MergeVars added in v0.3.0

func MergeVars(vars ...Vars) Vars

MergeVars merges a variadic array of variable sets.

type ViewFuncs

type ViewFuncs struct{}

ViewFuncs is the type stub for view functions.

func (ViewFuncs) AtIndex added in v0.3.4

func (vf ViewFuncs) AtIndex(index int, collection interface{}) (interface{}, error)

AtIndex returns an element at a given index.

func (ViewFuncs) Base64 added in v0.2.0

func (vf ViewFuncs) Base64(v string) string

Base64 encodes data as a string as a base6 string.

func (ViewFuncs) Base64Decode added in v0.2.0

func (vf ViewFuncs) Base64Decode(v string) (string, error)

Base64Decode decodes a base 64 string.

func (ViewFuncs) CSV added in v0.3.2

func (vf ViewFuncs) CSV(collection interface{}) (string, error)

CSV returns a csv of a given collection.

func (ViewFuncs) Ceil added in v0.2.0

func (vf ViewFuncs) Ceil(d float64) float64

Ceil returns the value rounded up to the nearest integer.

func (ViewFuncs) Concat added in v0.2.0

func (vf ViewFuncs) Concat(strs ...string) string

Concat concatenates a list of strings.

func (ViewFuncs) Contains added in v0.2.0

func (vf ViewFuncs) Contains(substr, v string) bool

Contains returns if a string contains a given substring.

func (ViewFuncs) DateMonthDay added in v0.2.0

func (vf ViewFuncs) DateMonthDay(t time.Time) string

DateMonthDay returns the month dat format for a timestamp. The format string is "1/2".

func (ViewFuncs) DateShort added in v0.2.0

func (vf ViewFuncs) DateShort(t time.Time) string

DateShort returns the short date for a timestamp. The format string is "1/02/2006"

func (ViewFuncs) Day added in v0.2.0

func (vf ViewFuncs) Day(t time.Time) int

Day returns the day component of a timestamp.

func (ViewFuncs) FileExists added in v0.2.0

func (vf ViewFuncs) FileExists(path string) bool

FileExists returns if the file at a given path exists.

func (ViewFuncs) First added in v0.2.0

func (vf ViewFuncs) First(collection interface{}) (interface{}, error)

First returns the first element of a collection.

func (ViewFuncs) Floor added in v0.2.0

func (vf ViewFuncs) Floor(d float64) float64

Floor returns the value rounded down to zero.

func (ViewFuncs) FormatMoney added in v0.2.0

func (vf ViewFuncs) FormatMoney(d float64) string

FormatMoney returns a float as a formatted string rounded to two decimal places.

func (ViewFuncs) FormatPct added in v0.2.0

func (vf ViewFuncs) FormatPct(d float64) string

FormatPct formats a float as a percentage (it is multiplied by 100, then suffixed with '%')

func (ViewFuncs) FuncMap added in v0.2.0

func (vf ViewFuncs) FuncMap() map[string]interface{}

FuncMap returns the name => func mapping.

func (ViewFuncs) GenerateKey added in v0.2.0

func (vf ViewFuncs) GenerateKey(keySize int) string

GenerateKey generates a key of a given size base 64 encoded.

func (ViewFuncs) GenerateOrdinalNames added in v0.2.0

func (vf ViewFuncs) GenerateOrdinalNames(format string, replicas int) []string

GenerateOrdinalNames generates ordinal names by passing the index to a given formatter. The formatter should be in Sprintf format (i.e. using a '%d' token for where the index should go).

Example:

{{ generate_ordinal_names "worker-%d" 3 }} // [worker-0 worker-1 worker-2]

func (ViewFuncs) HMAC512 added in v0.2.0

func (vf ViewFuncs) HMAC512(key, v string) (string, error)

HMAC512 returns the hmac signed sha 512 sum of a string.

func (ViewFuncs) HasPrefix added in v0.2.0

func (vf ViewFuncs) HasPrefix(prefix, v string) bool

HasPrefix returns if a string has a given prefix.

func (ViewFuncs) HasSuffix added in v0.2.0

func (vf ViewFuncs) HasSuffix(suffix, v string) bool

HasSuffix returns if a string has a given suffix.

func (ViewFuncs) Hour added in v0.2.0

func (vf ViewFuncs) Hour(t time.Time) int

Hour returns the hour component of a timestamp.

func (ViewFuncs) IndentSpaces added in v0.2.0

func (vf ViewFuncs) IndentSpaces(spaceCount int, v interface{}) string

IndentSpaces indents a string by a given set of spaces.

func (ViewFuncs) IndentTabs added in v0.2.0

func (vf ViewFuncs) IndentTabs(tabCount int, v interface{}) string

IndentTabs indents a string with a given number of tabs.

func (ViewFuncs) JSONEncode added in v0.2.0

func (vf ViewFuncs) JSONEncode(v interface{}) (string, error)

JSONEncode returns an object encoded as json.

func (ViewFuncs) JSONEncodePretty added in v0.2.0

func (vf ViewFuncs) JSONEncodePretty(v interface{}) (string, error)

JSONEncodePretty encodes an object as json with indentation.

func (ViewFuncs) Join added in v0.2.0

func (vf ViewFuncs) Join(sep string, collection interface{}) (string, error)

Join creates a string joined with a given separator.

func (ViewFuncs) Last added in v0.2.0

func (vf ViewFuncs) Last(collection interface{}) (interface{}, error)

Last returns the last element of a collection.

func (ViewFuncs) MD5 added in v0.2.0

func (vf ViewFuncs) MD5(v string) string

MD5 returns the md5 sum of a string.

func (ViewFuncs) Matches added in v0.2.0

func (vf ViewFuncs) Matches(expr, v string) (bool, error)

Matches returns if a string matches a given regular expression.

func (ViewFuncs) Millisecond added in v0.2.0

func (vf ViewFuncs) Millisecond(t time.Time) int

Millisecond returns the millisecond component of a timestamp.

func (ViewFuncs) Minute added in v0.2.0

func (vf ViewFuncs) Minute(t time.Time) int

Minute returns the minute component of a timestamp.

func (ViewFuncs) Month added in v0.2.0

func (vf ViewFuncs) Month(t time.Time) int

Month returns the month component of a timestamp.

func (ViewFuncs) Now added in v0.2.0

func (vf ViewFuncs) Now() time.Time

Now returns the current time in the system timezone.

func (ViewFuncs) NowUTC added in v0.2.0

func (vf ViewFuncs) NowUTC() time.Time

NowUTC returns the current time in the UTC timezone.

func (ViewFuncs) ParseBool added in v0.2.0

func (vf ViewFuncs) ParseBool(raw interface{}) (bool, error)

ParseBool attempts to parse a value as a bool. "truthy" values include "true", "1", "yes". "falsey" values include "false", "0", "no".

func (ViewFuncs) ParseJSON added in v0.2.0

func (vf ViewFuncs) ParseJSON(v string) (interface{}, error)

ParseJSON returns an object encoded as json.

func (ViewFuncs) ParseSemver added in v0.2.0

func (vf ViewFuncs) ParseSemver(v string) (*semver.Version, error)

ParseSemver parses a semantic version string.

func (ViewFuncs) ParseTime added in v0.2.0

func (vf ViewFuncs) ParseTime(format, v string) (time.Time, error)

ParseTime parses a time string with a given format.

func (ViewFuncs) ParseURL added in v0.2.0

func (vf ViewFuncs) ParseURL(v string) (*url.URL, error)

ParseURL parses a url.

func (ViewFuncs) ParseUUID added in v0.2.0

func (vf ViewFuncs) ParseUUID(v string) (uuid.UUID, error)

ParseUUID parses a uuid.

func (ViewFuncs) ParseUnix added in v0.2.0

func (vf ViewFuncs) ParseUnix(v int64) time.Time

ParseUnix returns a timestamp from a unix format.

func (ViewFuncs) ParseYAML added in v0.2.0

func (vf ViewFuncs) ParseYAML(v string) (interface{}, error)

ParseYAML decodes a corups as yaml.

func (ViewFuncs) Prefix added in v0.2.0

func (vf ViewFuncs) Prefix(pref, v string) string

Prefix appends a given string to a prefix.

func (ViewFuncs) Process added in v0.3.0

func (vf ViewFuncs) Process(vm Viewmodel, contents string) (string, error)

Process processes the given contents using a given template viewmodel

func (ViewFuncs) Quote added in v0.3.2

func (vf ViewFuncs) Quote(v string) string

Quote returns a string wrapped in " characters. It will trim space before and after, and only add quotes if they don't already exist.

func (ViewFuncs) RFC3339 added in v0.2.0

func (vf ViewFuncs) RFC3339(t time.Time) string

RFC3339 returns the RFC3339 format for a timestamp.

func (ViewFuncs) RandomLetters added in v0.2.0

func (vf ViewFuncs) RandomLetters(length int) string

RandomLetters returns a string of random letters.

func (ViewFuncs) RandomLettersWithNumbers added in v0.2.0

func (vf ViewFuncs) RandomLettersWithNumbers(count int) string

RandomLettersWithNumbers returns a string of random letters.

func (ViewFuncs) RandomLettersWithNumbersAndSymbols added in v0.2.0

func (vf ViewFuncs) RandomLettersWithNumbersAndSymbols(count int) string

RandomLettersWithNumbersAndSymbols returns a string of random letters.

func (ViewFuncs) ReadFile added in v0.2.0

func (vf ViewFuncs) ReadFile(path string) (string, error)

ReadFile reads the contents of a file path as a string.

func (ViewFuncs) Round added in v0.2.0

func (vf ViewFuncs) Round(places, d float64) float64

Round returns the value rounded to a given set of places. It uses midpoint rounding.

func (ViewFuncs) SHA1 added in v0.2.0

func (vf ViewFuncs) SHA1(v string) string

SHA1 returns the sha1 sum of a string.

func (ViewFuncs) SHA256 added in v0.2.0

func (vf ViewFuncs) SHA256(v string) string

SHA256 returns the sha256 sum of a string.

func (ViewFuncs) SHA512 added in v0.2.0

func (vf ViewFuncs) SHA512(v string) string

SHA512 returns the sha512 sum of a string.

func (ViewFuncs) Second added in v0.2.0

func (vf ViewFuncs) Second(t time.Time) int

Second returns the seconds component of a timestamp.

func (ViewFuncs) SemverBumpMajor added in v0.2.0

func (vf ViewFuncs) SemverBumpMajor(v *semver.Version) *semver.Version

SemverBumpMajor returns a semver with an incremented major version.

func (ViewFuncs) SemverBumpMinor added in v0.2.0

func (vf ViewFuncs) SemverBumpMinor(v *semver.Version) *semver.Version

SemverBumpMinor returns a semver with an incremented minor version.

func (ViewFuncs) SemverBumpPatch added in v0.2.0

func (vf ViewFuncs) SemverBumpPatch(v *semver.Version) *semver.Version

SemverBumpPatch returns a semver with an incremented patch version.

func (ViewFuncs) SemverMajor added in v0.2.0

func (vf ViewFuncs) SemverMajor(v *semver.Version) int

SemverMajor returns the major component of a semver.

func (ViewFuncs) SemverMinor added in v0.2.0

func (vf ViewFuncs) SemverMinor(v *semver.Version) int

SemverMinor returns the minor component of a semver.

func (ViewFuncs) SemverPatch added in v0.2.0

func (vf ViewFuncs) SemverPatch(v *semver.Version) int

SemverPatch returns the patch component of a semver.

func (ViewFuncs) Since added in v0.2.0

func (vf ViewFuncs) Since(t time.Time) time.Duration

Since returns the duration since a given timestamp. It is relative, meaning the value returned can be negative.

func (ViewFuncs) SinceUTC added in v0.2.0

func (vf ViewFuncs) SinceUTC(t time.Time) time.Duration

SinceUTC returns the duration since a given timestamp in UTC. It is relative, meaning the value returned can be negative.

func (ViewFuncs) Slice added in v0.2.0

func (vf ViewFuncs) Slice(from, to int, collection interface{}) (interface{}, error)

Slice returns a subrange of a collection.

func (ViewFuncs) Split added in v0.2.0

func (vf ViewFuncs) Split(sep, v string) []string

Split splits a string by a separator.

func (ViewFuncs) SplitN added in v0.2.0

func (vf ViewFuncs) SplitN(sep string, n float64, v string) []string

SplitN splits a string by a separator a given number of times.

func (ViewFuncs) StripQuotes added in v1.0.0

func (vf ViewFuncs) StripQuotes(v string) string

StripQuotes strips leading and trailing quotes.

func (ViewFuncs) Suffix added in v0.2.0

func (vf ViewFuncs) Suffix(suf, v string) string

Suffix appends a given prefix to a string.

func (ViewFuncs) TSV added in v0.3.2

func (vf ViewFuncs) TSV(collection interface{}) (string, error)

TSV returns a tab separated values of a given collection.

func (ViewFuncs) TimeFormat added in v1.0.0

func (vf ViewFuncs) TimeFormat(format string, t time.Time) string

TimeFormat returns the time with a given format string.

func (ViewFuncs) TimeInLocation added in v0.2.0

func (vf ViewFuncs) TimeInLocation(loc string, t time.Time) (time.Time, error)

TimeInLocation returns the time in a given location by string. If the location is invalid, this will error.

func (ViewFuncs) TimeInUTC added in v1.0.0

func (vf ViewFuncs) TimeInUTC(t time.Time) time.Time

TimeInUTC returns the time in a given location by string. If the location is invalid, this will error.

func (ViewFuncs) TimeKitchen added in v0.2.0

func (vf ViewFuncs) TimeKitchen(t time.Time) string

TimeKitchen returns the kitchen format for a timestamp. The format string is "3:04PM".

func (ViewFuncs) TimeMedium added in v0.2.0

func (vf ViewFuncs) TimeMedium(t time.Time) string

TimeMedium returns the medium format for a timestamp. The format string is "1/02/2006 3:04:05 PM".

func (ViewFuncs) TimeShort added in v0.2.0

func (vf ViewFuncs) TimeShort(t time.Time) string

TimeShort returns the short format for a timestamp. The format string is "1/02/2006 3:04:05 PM".

func (ViewFuncs) ToBytes added in v0.2.0

func (vf ViewFuncs) ToBytes(v interface{}) []byte

ToBytes attempts to return a bytes representation of a value.

func (ViewFuncs) ToFloat64 added in v0.2.0

func (vf ViewFuncs) ToFloat64(v string) (float64, error)

ToFloat64 parses a value as a float64.

func (ViewFuncs) ToInt added in v0.2.0

func (vf ViewFuncs) ToInt(v interface{}) (int, error)

ToInt parses a value as an integer.

func (ViewFuncs) ToInt64 added in v0.2.0

func (vf ViewFuncs) ToInt64(v interface{}) (int64, error)

ToInt64 parses a value as an int64.

func (ViewFuncs) ToLower added in v0.2.0

func (vf ViewFuncs) ToLower(v string) string

ToLower returns a string case shifted to lower case.

func (ViewFuncs) ToString added in v0.2.0

func (vf ViewFuncs) ToString(v interface{}) string

ToString attempts to return a string representation of a value.

func (ViewFuncs) ToTitle added in v0.2.0

func (vf ViewFuncs) ToTitle(v string) string

ToTitle returns a title cased string.

func (ViewFuncs) ToUpper added in v0.2.0

func (vf ViewFuncs) ToUpper(v string) string

ToUpper returns a string case shifted to upper case.

func (ViewFuncs) TrimPrefix added in v1.0.0

func (vf ViewFuncs) TrimPrefix(prefix, v string) string

TrimPrefix returns if a string has a given prefix.

func (ViewFuncs) TrimSpace added in v0.2.0

func (vf ViewFuncs) TrimSpace(v string) string

TrimSpace trims whitespace from the beginning and end of a string.

func (ViewFuncs) TrimSuffix added in v1.0.0

func (vf ViewFuncs) TrimSuffix(suffix, v string) string

TrimSuffix returns if a string has a given suffix.

func (ViewFuncs) URLHost added in v0.2.0

func (vf ViewFuncs) URLHost(v *url.URL) string

URLHost returns the host of a url.

func (ViewFuncs) URLPath added in v0.2.0

func (vf ViewFuncs) URLPath(v *url.URL) string

URLPath returns the url path.

func (ViewFuncs) URLPort added in v0.2.0

func (vf ViewFuncs) URLPort(v *url.URL) string

URLPort returns the url port. If none is explicitly specified, this will return empty string.

func (ViewFuncs) URLQuery added in v0.2.0

func (vf ViewFuncs) URLQuery(name string, v *url.URL) string

URLQuery returns a url query param.

func (ViewFuncs) URLRawQuery added in v0.2.0

func (vf ViewFuncs) URLRawQuery(v *url.URL) string

URLRawQuery returns the url raw query.

func (ViewFuncs) URLScheme added in v0.2.0

func (vf ViewFuncs) URLScheme(v *url.URL) string

URLScheme returns the scheme of a url.

func (ViewFuncs) UUIDv4 added in v0.2.0

func (vf ViewFuncs) UUIDv4() uuid.UUID

UUIDv4 generates a uuid v4.

func (ViewFuncs) Unix added in v0.2.0

func (vf ViewFuncs) Unix(t time.Time) string

Unix returns the unix format for a timestamp.

func (ViewFuncs) WithURLHost added in v0.2.0

func (vf ViewFuncs) WithURLHost(host string, v *url.URL) *url.URL

WithURLHost returns the host of a url.

func (ViewFuncs) WithURLPath added in v0.2.0

func (vf ViewFuncs) WithURLPath(path string, v *url.URL) *url.URL

WithURLPath returns the url path.

func (ViewFuncs) WithURLPort added in v0.2.0

func (vf ViewFuncs) WithURLPort(port string, v *url.URL) *url.URL

WithURLPort sets the url port.

func (ViewFuncs) WithURLQuery added in v0.2.0

func (vf ViewFuncs) WithURLQuery(key, value string, v *url.URL) *url.URL

WithURLQuery returns a url query param.

func (ViewFuncs) WithURLRawQuery added in v0.2.0

func (vf ViewFuncs) WithURLRawQuery(rawQuery string, v *url.URL) *url.URL

WithURLRawQuery returns the url path.

func (ViewFuncs) WithURLScheme added in v0.2.0

func (vf ViewFuncs) WithURLScheme(scheme string, v *url.URL) *url.URL

WithURLScheme returns the scheme of a url.

func (ViewFuncs) YAMLEncode added in v0.2.0

func (vf ViewFuncs) YAMLEncode(v interface{}) (string, error)

YAMLEncode returns an object encoded as yaml.

func (ViewFuncs) Year added in v0.2.0

func (vf ViewFuncs) Year(t time.Time) int

Year returns the year component of a timestamp.

type Viewmodel added in v0.3.0

type Viewmodel struct {
	// contains filtered or unexported fields
}

Viewmodel is the template viewmodel. It surfaces a subset of the template api. It is set / accessed by the outer template.

func (Viewmodel) Env added in v0.3.0

func (vm Viewmodel) Env(key string, defaults ...string) (string, error)

Env returns an environment variable.

func (Viewmodel) ExpandEnv added in v0.3.0

func (vm Viewmodel) ExpandEnv(s string) string

ExpandEnv replaces $var or ${var} based on the configured environment variables.

func (Viewmodel) HasEnv added in v0.3.0

func (vm Viewmodel) HasEnv(key string) bool

HasEnv returns if an env var is set.

func (Viewmodel) HasVar added in v0.3.0

func (vm Viewmodel) HasVar(key string) bool

HasVar returns if a variable is set.

func (Viewmodel) Var added in v0.3.0

func (vm Viewmodel) Var(key string, defaults ...interface{}) (interface{}, error)

Var returns the value of a variable, or panics if the variable is not set.

func (Viewmodel) Vars added in v0.3.2

func (vm Viewmodel) Vars() Vars

Vars returns the vars collection.

Jump to

Keyboard shortcuts

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