I have some very simple golang code:
func main (){
type config struct {
interval int `mapstructure:"Interval"`
statsdPrefix string `mapstructure:"statsd_prefix"`
groups []group
}
type group struct {
group string `mapstructure:"group"`
targetPrefix string `mapstructure:"target_prefix"`
targets []target
}
}
When I run this, I get the following:
undefined: group
What am I missing here?
Since you've defined the types in a function, the config type definition runs before there is a group type to reference. Reversing the order of your definitions works, although I had to remove the reference to target as you have not provided it's definition.
This works in the playgound https://play.golang.org/p/fzRCtCHqnH:
func main() {
type group struct {
group string `mapstructure:"group"`
targetPrefix string `mapstructure:"target_prefix"`
}
type config struct {
interval int `mapstructure:"Interval"`
statsdPrefix string `mapstructure:"statsd_prefix"`
groups []group
}
}