Add the sprig functions in the template engine
This commit is contained in:
parent
ff11467022
commit
7ff6c32452
42 changed files with 5671 additions and 50 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"unicode"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/Masterminds/sprig"
|
||||
"github.com/containous/traefik/autogen"
|
||||
"github.com/containous/traefik/log"
|
||||
"github.com/containous/traefik/safe"
|
||||
|
@ -59,14 +60,12 @@ func (p *BaseProvider) GetConfiguration(defaultTemplateFile string, funcMap temp
|
|||
err error
|
||||
)
|
||||
configuration := new(types.Configuration)
|
||||
var defaultFuncMap = template.FuncMap{
|
||||
"replace": Replace,
|
||||
"tolower": strings.ToLower,
|
||||
"normalize": Normalize,
|
||||
"split": split,
|
||||
"contains": contains,
|
||||
}
|
||||
|
||||
var defaultFuncMap = sprig.TxtFuncMap()
|
||||
// tolower is deprecated in favor of sprig's lower function
|
||||
defaultFuncMap["tolower"] = strings.ToLower
|
||||
defaultFuncMap["normalize"] = Normalize
|
||||
defaultFuncMap["split"] = split
|
||||
for funcID, funcElement := range funcMap {
|
||||
defaultFuncMap[funcID] = funcElement
|
||||
}
|
||||
|
@ -102,15 +101,6 @@ func (p *BaseProvider) GetConfiguration(defaultTemplateFile string, funcMap temp
|
|||
return configuration, nil
|
||||
}
|
||||
|
||||
// Replace is an alias for strings.Replace
|
||||
func Replace(s1 string, s2 string, s3 string) string {
|
||||
return strings.Replace(s3, s1, s2, -1)
|
||||
}
|
||||
|
||||
func contains(substr, s string) bool {
|
||||
return strings.Contains(s, substr)
|
||||
}
|
||||
|
||||
func split(sep, s string) []string {
|
||||
return strings.Split(s, sep)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue