Created
August 7, 2019 16:04
-
-
Save mapix/0fc8e4193d3ea92199e4f9f6fd2afbf6 to your computer and use it in GitHub Desktop.
trick for default funcmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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