I can not find it in the documentation, is there a guarantee that the order from the fields will correspond to the order declared in the structure? I know that it looks like this is logical (due to the memory layout), and it seems that is also the case, but just make sure. I do not want the code to be interrupted later if this is not a guarantee.
For example, if I had
type Foo struct { bar string `tag:"bar"` baz string `tag:"baz"` barbaz string `tag:"barbaz"` }
and I ran this code:
var c Foo t := reflect.TypeOf(c) nf := t.NumField() tags := make([]string, nf) for f := 0; f < nf; f++ { tags[f] = t.Field(f).Tag.Get("tag") }
Will the tags be ["bar", "baz", "barbaz"] ?
source share