Skip to content

Instantly share code, notes, and snippets.

@mapix
Created August 7, 2019 16:04
Show Gist options
  • Save mapix/0fc8e4193d3ea92199e4f9f6fd2afbf6 to your computer and use it in GitHub Desktop.
Save mapix/0fc8e4193d3ea92199e4f9f6fd2afbf6 to your computer and use it in GitHub Desktop.
trick for default funcmap
package main
import (
"os"
"text/template"
"strings"
)
func main() {
fmap := template.FuncMap{
"split": strings.Split,
}
t := template.Must(template.New("abc").Funcs(fmap).Parse(
`
{{- $z := (split (index . "sage_distribution_features") ",") -}}
{{- if (eq (index $z 0) "task-controller") or (eq (index $z 1) "task-controller") or (eq (index $z 2) "task-controller") or (eq (index $z 3) "task-controller") or (eq (index $z 4) "task-controller") or (eq (index $z 5) "task-controller") or (eq (index $z 6) "task-controller") or (eq (index $z 7) "task-controller") or (eq (index $z 8) "task-controller") -}}
aaaaaaaaaaaaaaaaaaaa
{{- else -}}
bbbbbbbbbbbbbbbbbbbb
{{- end -}}
`))
a := make(map[string]string)
//a["xby"] = "iii"
a["sage_distribution_features"] = "task-controller,xyz"
t.Execute(os.Stdout, a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment