Skip to content

Commit

Permalink
Changed to fluent style inserts on influxdb
Browse files Browse the repository at this point in the history
  • Loading branch information
oscaromeu committed Dec 6, 2021
1 parent c712127 commit e91490b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions examples/influxdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bytes"
"context"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -245,19 +244,20 @@ func main() {
str := fmt.Sprintf("%s-%s-%sT%s:%s:%s", p.Any, p.Mes, p.Dia, p.Hour, p.Minute, p.Seconds)

tt, err := time.Parse(layout, str)
writeAPI := c.WriteAPIBlocking("", "meteocat/autogen")
writeAPI := c.WriteAPI("", "meteocat/autogen")

for _, v := range d.OpenData {
Tags["codi_estacio"] = v.CodiEstacio
Tags["nom_estacio"] = meteocat.CodisEstacions[v.CodiEstacio]
Tags["codi_variable"] = v.CodiVariable
Tags["nom_variable"] = meteocat.CodisVariables[v.CodiVariable]
Fields["valor"] = v.ValorLectura
p := client.NewPoint(cfg.InfluxMeasurement,
Tags,
Fields, tt)
// write point asynchronously
writeAPI.WritePoint(context.Background(), p)
// create point using fluent style
p := client.NewPointWithMeasurement(cfg.InfluxMeasurement).
AddTag("codi_estacio", v.CodiEstacio).
AddTag("nom_estacio", meteocat.CodisEstacions[v.CodiEstacio]).
AddTag("codi_variable", v.CodiVariable).
AddTag("nom_variable", meteocat.CodisVariables[v.CodiVariable]).
AddField("max", v.ValorLectura).
SetTime(tt)
writeAPI.WritePoint(p)
// Flush writes
writeAPI.Flush()

}
// always close client at the end
Expand Down

0 comments on commit e91490b

Please sign in to comment.