funcmap

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: BlueOak-1.0.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Funcs = map[string]interface{}{
	"append":       Append,
	"base64Decode": DecodeBase64,
	"base64Encode": EncodeBase64,
	"chomp":        Chomp,
	"contains":     Contains,
	"containsAny":  ContainsAny,
	"dateFormat":   TimeFormat,
	"env":          Getenv,
	"fileExists":   FileExists,
	"htmlEscape":   HTMLEscape,
	"htmlUnescape": HTMLUnescape,
	"hasPrefix":    HasPrefix,
	"hasSuffix":    HasSuffix,
	"indent":       Indent,
	"jsonify":      EncodeJSON,
	"lower":        ToLower,
	"md5":          MD5,
	"nindent":      NIndent,
	"now":          Now,
	"padLeft":      PadLeft,
	"padRight":     PadRight,
	"prepend":      Prepend,
	"readDir":      ReadDir,
	"readFile":     ReadFile,
	"replace":      Replace,
	"sha1":         SHA1,
	"sha256":       SHA256,
	"split":        Split,
	"splitn":       SplitN,
	"title":        ToTitle,
	"time":         Time,
	"trimLeft":     TrimLeft,
	"trimRight":    TrimRight,
	"trimPrefix":   TrimPrefix,
	"trimSuffix":   TrimSuffix,
	"trim":         Trim,
	"upper":        ToUpper,
	"urlize":       Urlize,
	"toYaml":       ToYAML,
}

Funcs is a map of custom template functions.

View Source
var SafeFuncs = map[string]interface{}{
	"append":       Append,
	"base64Decode": DecodeBase64,
	"base64Encode": EncodeBase64,
	"chomp":        Chomp,
	"contains":     Contains,
	"containsAny":  ContainsAny,
	"dateFormat":   TimeFormat,
	"htmlEscape":   HTMLEscape,
	"htmlUnescape": HTMLUnescape,
	"hasPrefix":    HasPrefix,
	"hasSuffix":    HasSuffix,
	"indent":       Indent,
	"jsonify":      EncodeJSON,
	"lower":        ToLower,
	"md5":          MD5,
	"nindent":      NIndent,
	"now":          Now,
	"padLeft":      PadLeft,
	"padRight":     PadRight,
	"prepend":      Prepend,
	"replace":      Replace,
	"sha1":         SHA1,
	"sha256":       SHA256,
	"split":        Split,
	"splitn":       SplitN,
	"title":        ToTitle,
	"time":         Time,
	"trimLeft":     TrimLeft,
	"trimRight":    TrimRight,
	"trimPrefix":   TrimPrefix,
	"trimSuffix":   TrimSuffix,
	"trim":         Trim,
	"upper":        ToUpper,
	"urlize":       Urlize,
	"toYaml":       ToYAML,
}

SafeFuncs is a map of custom template functions. Functions that expose the environment and filesystem are excluded.

Functions

func Append

func Append(s, append interface{}) (string, error)

Append returns a slice of the string s, with append appended.

func Chomp

func Chomp(s interface{}) (string, error)

Chomp returns a copy of s with all trailing newline characters removed.

func Combine

func Combine(funcmaps ...map[string]interface{}) template.FuncMap

Combine combines function maps.

func Contains

func Contains(s, substr interface{}) (bool, error)

Contains reports whether substr is within s.

func ContainsAny

func ContainsAny(s, chars interface{}) (bool, error)

ContainsAny reports whether any Unicode code points in chars are within s.

func DecodeBase64

func DecodeBase64(s interface{}) (string, error)

DecodeBase64 returns the base64 decoding of s.

func EncodeBase64

func EncodeBase64(s interface{}) (string, error)

EncodeBase64 returns the base64 encoding of s.

func EncodeJSON

func EncodeJSON(v interface{}) (template.HTML, error)

EncodeJSON returns the JSON encoding of v.

func FileExists

func FileExists(name interface{}) (bool, error)

FileExists returns true if the file exists.

func Getenv

func Getenv(key interface{}) (string, error)

Getenv retrieves the value of the environment variable named by the key.

func HTMLEscape

func HTMLEscape(s interface{}) (string, error)

HTMLEscape returns a copy of s with reserved HTML characters escaped.

func HTMLUnescape

func HTMLUnescape(s interface{}) (string, error)

HTMLUnescape returns a copy of s with HTML escape sequences converted to plain text.

func HasPrefix

func HasPrefix(s interface{}, prefix string) (bool, error)

HasPrefix tests whether the string s begins with prefix.

func HasSuffix

func HasSuffix(s interface{}, suffix string) (bool, error)

HasSuffix tests whether the string s ends with suffix.

func Indent

func Indent(s interface{}, n int) (string, error)

Indent returns a copy of the string s, with all lines prefixed with n spaces

func MD5

func MD5(s interface{}) (string, error)

MD5 returns the sha checksum of s.

func NIndent

func NIndent(s interface{}, n int) (string, error)

NIndent returns a copy of the string s, with all lines prefixed with n spaces, and a newline at the start. This is useful when interpolating into yaml, where you want each line indented by the exact same amount, but

func Now

func Now() time.Time

Now returns the current local time.

func PadLeft

func PadLeft(s, padding interface{}, n int) (string, error)

PadLeft returns a slice of the string s, prefixed with n copies of padding.

func PadRight

func PadRight(s, padding interface{}, n int) (string, error)

PadRight returns a slice of the string s, suffixed with n instances of the padding string.

func Prepend

func Prepend(s, prepend interface{}) (string, error)

Prepend returns a slice of the string s, prepended with prepend.

func ReadDir

func ReadDir(dirname interface{}) ([]os.FileInfo, error)

ReadDir reads the directory named by dirname and returns a list of directory entries sorted by filename.

func ReadFile

func ReadFile(filename interface{}) ([]byte, error)

ReadFile reads the directory named by dirname and returns a list of directory entries sorted by filename.

func Replace

func Replace(s, old, new interface{}) (string, error)

Replace returns a copy of the string s with instances of old replaced by new.

func SHA1

func SHA1(s interface{}) (string, error)

SHA1 returns the sha checksum of s.

func SHA256

func SHA256(s interface{}) (string, error)

SHA256 returns the sha checksum of s.

func Split

func Split(s interface{}, sep string) ([]string, error)

Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators.

func SplitN

func SplitN(s interface{}, sep string, n int) ([]string, error)

SplitN slices s into substrings separated by sep and returns a slice of the substrings between those separators.

func Time

func Time(v interface{}, args ...interface{}) (interface{}, error)

Time converts the textual representation of the datetime string into a time.Time interface.

func TimeFormat

func TimeFormat(layout string, v interface{}) (string, error)

TimeFormat converts the textual representation of the datetime string into the other form or returns it of the time.Time value. These are formatted with the layout string

func ToLower

func ToLower(s interface{}) (string, error)

ToLower returns a copy of the input s with all Unicode letters mapped to their lower case.

func ToTitle

func ToTitle(s interface{}) (string, error)

ToTitle returns a copy of the input s with all Unicode letters mapped to their title case.

func ToUpper

func ToUpper(s interface{}) (string, error)

ToUpper returns a copy of the input s with all Unicode letters mapped to their upper case.

func ToYAML

func ToYAML(s interface{}) (string, error)

toYAML takes an interface, marshals it to yaml, and returns a string. It will always return a string, even on marshal error (empty string).

This is designed to be called from a template.

func Trim

func Trim(s interface{}) (string, error)

Trim returns a slice of the string s, with all leading and trailing white space removed, as defined by Unicode.

func TrimLeft

func TrimLeft(s interface{}, custet string) (string, error)

TrimLeft returns a slice of the string s with all leading Unicode code points contained in cutset removed.

func TrimPrefix

func TrimPrefix(s interface{}, prefix string) (string, error)

TrimPrefix returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

func TrimRight

func TrimRight(s interface{}, custet string) (string, error)

TrimRight returns a slice of the string s, with all trailing Unicode code points contained in cutset removed.

func TrimSuffix

func TrimSuffix(s interface{}, suffix string) (string, error)

TrimSuffix returns s without the provided trailing suffix string. If s doesn't end with suffix, s is returned unchanged.

func Urlize

func Urlize(s interface{}) (string, error)

Urlize returns a copy of the input s that is sanities so it can be safely placed inside a URL path segment, with spaces converted to hypens.

Types

This section is empty.

Jump to

Keyboard shortcuts

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