From: Cameron Moore Date: Fri, 23 Dec 2016 04:05:59 +0000 (-0600) Subject: tpl: Update getenv to accept interface{} params X-Git-Tag: v0.19~183 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=34c87421b82b967a8ae85261ca9a3e9fe7b156da;p=brevno-suite%2Fhugo tpl: Update getenv to accept interface{} params Updates #2822 --- diff --git a/tpl/template_funcs.go b/tpl/template_funcs.go index 7516b46a..db3ba37b 100644 --- a/tpl/template_funcs.go +++ b/tpl/template_funcs.go @@ -2075,6 +2075,17 @@ func relURL(a interface{}) (template.HTML, error) { return template.HTML(helpers.CurrentPathSpec().RelURL(s, false)), nil } +// getenv retrieves the value of the environment variable named by the key. +// It returns the value, which will be empty if the variable is not present. +func getenv(key interface{}) (string, error) { + skey, err := cast.ToStringE(key) + if err != nil { + return "", nil + } + + return os.Getenv(skey), nil +} + func initFuncMap() { funcMap = template.FuncMap{ "absURL": absURL, @@ -2106,7 +2117,7 @@ func initFuncMap() { "ge": ge, "getCSV": getCSV, "getJSON": getJSON, - "getenv": func(varName string) string { return os.Getenv(varName) }, + "getenv": getenv, "gt": gt, "hasPrefix": hasPrefix, "highlight": highlight,