我正在使用Golang項目,需要生成以下內容app1 && app2 && app3我的模板如下所示{{- range ExeApp .}} {{ .Command }} {{- end}}我的代碼看起來像是帶有字符串數組的命令type App struct { Data string Command []string}//This is the functionfunc ExeApp(m models) []App { switch m.Type { case “apps": return []App{ {"# running apps", []string{“app1", “app2", “app3"}}, }…目前其生成像[app1 app2 app3]我需要它app1 && app2 && app3 ,我嘗試通過在.Command之前添加&&來處理模板,這無濟于事,此外,我不知道如何在應用程序前后刪除數組[],知道我在這里做錯了什么嗎?我已經嘗試過以下{{- range .ExeApp}} {{range .Command }} && {{.}} {{end}} {{- end}}但是現在我正在轉儲并出現錯誤: unexpected EOF或未定義函數“ Command”在運行模板時生成的代碼是:funcMap := template.FuncMap{ "ExeApp": ExeApp,}t, err := template.New("file.txt").Funcs(funcMap).ParseFiles(container)如果我使用第一個結構(沒有字符串數組的相同結構,當然也要修改對象的代碼),那么一切都會按預期進行也嘗試這個 {{-range .ExeApp}} {{range .Command}} {{.}} {{end}} {{end}}現在我收到錯誤executing "file.txt" at <.ExeApp>: can't evaluate field ExeApp in type *models為什么 :(
- 1 回答
- 0 關注
- 492 瀏覽
添加回答
舉報
0/150
提交
取消