InfluxDB client for Go


#1

Hi,

I already Googled to find answers related to the Go InfluxDB client. But I’m really confused as what to use as Go client. When trying to install the v2 (github.com/influxdata/influxdb/client/v2) gives problems/errors.

I found finally this: go get github.com/influxdata/influxdb1-client/v2
Can someone confirm if installing this Go package is al I need to interface with an InfluxDB from Go?

Many thanks.
Guy


#2

Thats correct. Here is a code snippet for how to connect to InfluxDB:

import (
client “github.com/influxdata/influxdb1-client
)

func establishInfluxConnection(username string, password string, databaseURL string) *client.Client {
host, err := url.Parse(databaseURL)
if err != nil {
log.Fatal(err)
}

conf := client.Config{
	URL:      *host,
	Username: username,
	Password: password,
}
con, err := client.NewClient(conf)
if err != nil {
	log.Fatal(err)
}

return con

}

con := establishInfluxConnection(configuration.InfluxUsername, configuration.InfluxPassword, configuration.InfluxHost)