influxdbhelper
influxdbhelper copied to clipboard
Embedded struct error: all fields must have non-empty names
If I have a struct that uses "type embedding" to embed another struct, even if the embedded struct has influx tags on its fields, influxdbhelper complains:
Error writing ... data to influx: all fields must have non-empty names
Ideally, embedded structs should be supported.
Do you have any thoughts on naming fields of embedded structs in influx, as influx records are flat?
I think influxdbhelper should flatten embedded structs. The Go compiler supports this strange flattening property of embedded structs. For example, if you have:
type A struct {
FieldA string `influx: fieldA,tag`
}
type B struct {
A
FieldB string `influx: fieldB,tag`
}
In this case, B.A.FieldA and B.FieldA are synonymous, and it appears that the embedded struct has been "flattened" in the latter case. Disclaimer: I'm unsure how the reflection API in Go works for embedded structs.
This might be helpful: https://stackoverflow.com/questions/24333494/golang-reflection-on-embedded-structs
agreed, it would be handy to be able to "compose" structs and essentially flatten them for storage in influx.
The workaround for now is to create another struct for writing into influx, and then copy your data to that. Since influx schemas are generally not huge, this has not been a big problem.