I need to return form the text template key value which will be like comment and command like following
#Description for npm install
npm install
#Description for test
npm test
#Description for test2
run test2
For that I've created a function like the following:
// example with switch
func (d Dependency) TypeCommand() Command {
switch d.Type {
case "runner":
cmd1 := Command{"#Description for npm install", "npm install"}
cmd2 := Command{"#Description for test", "npm test"}
cmd3 := Command{"#Description for test2", "run test2"}
case "runner2":
return "test 2"
}
return "command_baz"
}
The template is:
const tmpl = `
{{- range .File.Dependency}}
{{.TypeCommand}}
{{end}}`
type Command struct {
Info string
Command string
}
When I change the template to the following, I get an error:
const tmpl = `
{{- range .File.Dependency}}
{{ TypeCommand .}}
{{ range .Command}}
{{ .Info }}
{{ .Command }}
{{end}}
{{end}}
'
executing "tmpl3.txt" at <.Command>: can't evaluate field Command in type *Dependency
I use this as reference.
--typeoption for every invocation, you might consider using subcommands instead:extract format --format=jsonorextract order --format=xmlTypeCommandwhy are you returning String and mentioning return type as Dependency ?Commandstruct andCommandstruct field were named different things.