-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfluxdb.go
43 lines (32 loc) · 1 KB
/
influxdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"log"
"os"
influxdb "github.com/influxdata/influxdb1-client/v2"
)
var influxClient influxdb.Client
var influxDatabase string
func init() {
var influxURL, influxUsername, influxPassword string
if influxURL = os.Getenv("INFLUXDB_URL"); influxURL == "" {
log.Fatal("environment variable: INFLUXDB_URL is not defined")
}
if influxDatabase = os.Getenv("INFLUXDB_DB"); influxDatabase == "" {
log.Fatal("environment variable: INFLUXDB_DB is not defined")
}
if influxUsername = os.Getenv("INFLUXDB_USER"); influxUsername == "" {
log.Fatal("environment variable: INFLUXDB_USER is not defined")
}
if influxPassword = os.Getenv("INFLUXDB_USER_PASSWORD"); influxPassword == "" {
log.Fatal("environment variable: INFLUXDB_USER_PASSWORD is not defined")
}
c, err := influxdb.NewHTTPClient(influxdb.HTTPConfig{
Addr: influxURL,
Username: influxUsername,
Password: influxPassword,
})
if err != nil {
log.Fatalf("Error creating InfluxDB Client: %s", err)
}
influxClient = c
}