Encode/Decode of influx data in Golang




I’m pondering writing a small golang library that can be used to decode influx data (much like Go json, bson, and mapstructure apis) that would populate an array of go structs with data from an influxdb query. I’m thinking you define a struct like:

type SensorData struct {
   Time time.Time  `influx:time`
   Location string   `influx:location,tag`
   Name string       `influx:name,tag`
   Value float64     `influx:value`
   Temp []float64    `influx:temp`

results := []SensorData{}

err := InfluxQuery(queryString, &results)

The struct tags would map the Go struct field names to the influx tag/field names. The Temp field in the above struct would be populated by looking for temp0, temp1, temp2, tempx fields in the influx data.

The above struct could also be used for writing data. The “tag” tags in the above go struct would tell the library which members of the struct should be influx tags. The rest would be fields.

This would simplify writing influx queries, and at the same time clearly document the influx database schema.

Does this approach seem to make sense, or does anything like this already exist?



I started a proof of concept library for these ideas:

So, far it seems to be working out pretty well.

Feedback welcome!


A few improvements to this package: