Im using Golang project which needs to generate the following
app1 && app2 && app3
My template look like following
{{- range ExeApp .}} {{ .Command }} {{- end}}
My code looks like following with command which is array of strings
type App struct {
Data string
Command []string
}
//This is the function
func ExeApp(m models) []App {
switch m.Type {
case “apps":
return []App{
{"# running apps",
[]string{“app1", “app2", “app3"}},
}
…
Currently its generated like
[app1 app2 app3]
And I need it like
app1 && app2 && app3
,
I try to play with the template by adding && before the .Command which doesn’t help and in addition I don’t know how to remove the array [] before and after the apps, any idea what I’m doing wrong here ?
i've tried with the following
{{- range .ExeApp}} {{range .Command }} && {{.}} {{end}} {{- end}}
But now im getting dump with error: unexpected EOF
or function "Command" not defined
while running the template
The code to generate is:
funcMap := template.FuncMap{
"ExeApp": ExeApp,
}
t, err := template.New("file.txt").Funcs(funcMap).ParseFiles(container)
in case Im working with the first structure (same structure without the array of strings and of course adapt the code of the object) everything is working as expected
Try also with this
{{-range .ExeApp}} {{range .Command}} {{.}} {{end}} {{end}}
Now im getting error
executing "file.txt" at <.ExeApp>: can't evaluate field ExeApp in type *models
why :(