Documentation
¶
Index ¶
- func All(t *template.Template) template.FuncMap
- func And(expr ...interface{}) interface{}
- func Bracket(s interface{}) string
- func BracketWith(b string, s interface{}) (string, error)
- func CombineFunctionLists(fnList ...template.FuncMap) template.FuncMap
- func Contains(list interface{}, item interface{}) (bool, error)
- func EncodingFunctions() template.FuncMap
- func Filter(list interface{}, item interface{}) (interface{}, error)
- func First(list interface{}) (interface{}, error)
- func FormatJSON(indent string, j string) (string, error)
- func FromBase64(s string) (string, error)
- func GenerateIncludeFn(t *template.Template) func(string, interface{}) (string, error)
- func Indent(t int, content string) string
- func IsZero(val interface{}) bool
- func Join(list interface{}) (string, error)
- func JoinWith(glue string, list interface{}) (string, error)
- func Last(list interface{}) (interface{}, error)
- func List(s ...interface{}) (interface{}, error)
- func ListFunctions() template.FuncMap
- func LogicFunctions() template.FuncMap
- func MiscellaneousFunctions() template.FuncMap
- func Newline(c ...int) string
- func Now() string
- func Or(expr ...interface{}) interface{}
- func PadLeft(n int, s interface{}) string
- func PadRight(n int, s interface{}) string
- func Pop(list interface{}) (interface{}, error)
- func Prefix(prefix string, t int, content string) string
- func Push(list interface{}, item interface{}) (interface{}, error)
- func QuoteBack(s interface{}) string
- func QuoteDouble(s interface{}) string
- func QuoteSingle(s interface{}) string
- func Rep(n int, s ...string) string
- func Rest(list interface{}) (interface{}, error)
- func Slice(i, j int, list interface{}) (interface{}, error)
- func Space(n int) string
- func SplitOn(glue string, s string) []string
- func StringFunctions() template.FuncMap
- func Suffix(suffix string, t int, content string) string
- func Tab(n int) string
- func TemplateFunctions(t *template.Template) template.FuncMap
- func TerminalWidth() int
- func TitleCaseWithAbbr(abbrev interface{}, word string) (string, error)
- func ToBase64(s string) string
- func ToColumn(w int, s string) string
- func ToJSON(val interface{}) (string, error)
- func ToYAML(val interface{}) (string, error)
- func TypeKind(val interface{}) string
- func TypeName(val interface{}) string
- func Unindent(t int, content string) (string, error)
- func Unshift(list interface{}, item interface{}) (interface{}, error)
- func UppercaseFirst(s interface{}) string
- func When(d, s interface{}) interface{}
- func WhenEmpty(d, s interface{}) interface{}
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶ added in v0.9.5
func And(expr ...interface{}) interface{}
And returns the value of the last expression if all expressions evaluate to non-zero, or empty string otherwise
func Bracket ¶ added in v0.6.3
func Bracket(s interface{}) string
Bracket adds brackets around the given string
func BracketWith ¶ added in v0.6.3
BracketWith adds brackets of a given type around the given string
func CombineFunctionLists ¶ added in v0.9.5
CombineFunctionLists together from zero more supplied lists
func Contains ¶ added in v0.7.2
Contains returns true if the item is present in the list
Example ¶
helperApplyAndRenderTemplate(contains, a)
Output: {{.a}} = [a b c d e] {{contains .a "x"}} = false {{contains .a "d"}} = true {{contains .a 3}} = false
func EncodingFunctions ¶ added in v0.9.5
EncodingFunctions for encoding and decoding various formats
func Filter ¶ added in v0.7.2
func Filter(list interface{}, item interface{}) (interface{}, error)
Filter returns list with all instances of item removed
Example ¶
helperApplyAndRenderTemplate(filter, a)
Output: {{.a}} = [a b c d e] {{filter .a "x"}} = [a b c d e] {{filter .a 3}} = [a b c d e] {{filter .a "c"}} = [a b d e] {{.b}} = [f o o b a r] {{filter .b "o"}} = [f b a r]
func First ¶
func First(list interface{}) (interface{}, error)
First returns the head of a list
Example ¶
helperApplyAndRenderTemplate(first, a)
Output: {{.a}} = [a b c d e] {{first .a}} = a
func FormatJSON ¶ added in v0.7.0
FormatJSON returns the given json string, formatted with the given indent string
func FromBase64 ¶ added in v0.8.1
FromBase64 decodes the given encoded string to plain
func GenerateIncludeFn ¶
GenerateIncludeFn creates a function to be used as an "include" function in templates
func Indent ¶
Indent prints the given string with the given number of spaces prepended before each line
func IsZero ¶ added in v0.6.3
func IsZero(val interface{}) bool
IsZero returns true if the value given corresponds to its types zero value, points to something zero valued, or if it's a type with a length which is 0
func JoinWith ¶ added in v0.7.0
JoinWith joins the given strings together using the given string as glue
func Last ¶
func Last(list interface{}) (interface{}, error)
Last returns the last item of a list
Example ¶
helperApplyAndRenderTemplate(last, a)
Output: {{.a}} = [a b c d e] {{last .a}} = e
func List ¶ added in v0.7.2
func List(s ...interface{}) (interface{}, error)
List returns a new list comprised of the given elements
Example ¶
helperApplyAndRenderTemplate(list, a)
Output: {{list "a" "b" "c"}} = [a b c] {{list "a" 5 false}} = [a 5 false] {{range list 1 2 3}}{{bracket .}}{{end}} = (1)(2)(3)
func ListFunctions ¶ added in v0.9.5
ListFunctions operate on collections of items
func LogicFunctions ¶ added in v0.9.5
LogicFunctions perform logical operations
func MiscellaneousFunctions ¶ added in v0.9.5
MiscellaneousFunctions are functions that don't have a more specific home
func Or ¶ added in v0.9.5
func Or(expr ...interface{}) interface{}
Or returns the first expression that evaluates to non-zero, or empty string if none do
func Pop ¶ added in v0.7.2
func Pop(list interface{}) (interface{}, error)
Pop removes the first element of the list, returning the list
Example ¶
helperApplyAndRenderTemplate(pop, a)
Output: {{.a}} = [a b c d e] {{pop .a}} = [a b c d]
func Prefix ¶ added in v0.8.0
Prefix prints the given string with the given number of 'prefix' prepended before each line
func Push ¶ added in v0.7.2
func Push(list interface{}, item interface{}) (interface{}, error)
Push returns the list with item appended
Example ¶
helperApplyAndRenderTemplate(push, a)
Output: {{.a}} = [a b c d e] {{push .a "x"}} = [a b c d e x]
func QuoteBack ¶ added in v0.9.4
func QuoteBack(s interface{}) string
QuoteBack adds back-quotes around the given string
func QuoteDouble ¶ added in v0.9.4
func QuoteDouble(s interface{}) string
QuoteDouble adds double quote around the given string
func QuoteSingle ¶ added in v0.9.4
func QuoteSingle(s interface{}) string
QuoteSingle adds single quote around the given string
func Rest ¶
func Rest(list interface{}) (interface{}, error)
Rest / Shift returns the tail of a list
Example ¶
helperApplyAndRenderTemplate(rest, a)
Output: {{.a}} = [a b c d e] {{rest .a}} = [b c d e]
func Slice ¶ added in v0.7.2
Slice returns a slice of a list where i is the lower index (inclusive) and j is the upper index (exclusive) to extract
Example ¶
helperApplyAndRenderTemplate(slice, a)
Output: {{.a}} = [a b c d e] {{slice 1 3 .a}} = [b c]
func SplitOn ¶ added in v0.7.0
SplitOn creates an array from the given string by separating it by the glue string
func StringFunctions ¶ added in v0.9.5
StringFunctions primary operate on strings
func Suffix ¶ added in v0.8.0
Suffix prints the given string with the given number of 'suffix' appended to each line
func TemplateFunctions ¶ added in v0.9.5
TemplateFunctions operate on templates themselves
func TerminalWidth ¶ added in v0.9.0
func TerminalWidth() int
TerminalWidth returns the number of columns that the terminal currently has, or 0 if the program isn't run in one, or it can't otherwise be determined
func TitleCaseWithAbbr ¶ added in v0.9.1
TitleCaseWithAbbr upper-cases the first letter of each word, or the whole word if it matches a given abbreviation
func ToColumn ¶ added in v0.9.0
ToColumn formats the given text to not take more than 'w' characters per line, splitting on the space before the word that would take the line over. If no space can be found, the line isn't split (ie words bigger than the line size are printed unsplit)
Example ¶
ExampleToColumn
w := 40 s := "Lorem ipsum dolor\nsit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." got := ToColumn(w, s) fmt.Println(got)
Output: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
func TypeKind ¶ added in v0.9.2
func TypeKind(val interface{}) string
TypeKind returns the 'kind” of the given value as a string
func TypeName ¶ added in v0.7.0
func TypeName(val interface{}) string
TypeName returns the type of the given value as a string
func Unindent ¶ added in v0.9.6
Unindent removes up to 't' spaces from the start of all lines within content
func Unshift ¶ added in v0.7.2
func Unshift(list interface{}, item interface{}) (interface{}, error)
Unshift returns the list with item prepended
Example ¶
helperApplyAndRenderTemplate(unshift, a)
Output: {{.a}} = [a b c d e] {{unshift .a "x"}} = [x a b c d e]
func UppercaseFirst ¶
func UppercaseFirst(s interface{}) string
UppercaseFirst converts the first character in a string to uppercase
Types ¶
This section is empty.