-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathclient_test.go
47 lines (36 loc) · 1.08 KB
/
client_test.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
44
45
46
47
package influxdbhelper
import (
"time"
)
func ExampleClient_WritePoint() {
c, _ := NewClient("http://localhost:8086", "", "", "ns")
type EnvSample struct {
Time time.Time `influx:"time"`
Location string `influx:"location,tag"`
Temperature float64 `influx:"temperature"`
Humidity float64 `influx:"humidity"`
ID string `influx:"-"`
}
s := EnvSample{
Time: time.Now(),
Location: "Rm 243",
Temperature: 70.0,
Humidity: 60.0,
ID: "12432as32",
}
c.UseDB("myDb").UseMeasurement("test").WritePoint(s)
}
func ExampleClient_Query() {
c, _ := NewClient("http://localhost:8086", "", "", "ns")
type EnvSample struct {
Time time.Time `influx:"time"`
Location string `influx:"location,tag"`
Temperature float64 `influx:"temperature"`
Humidity float64 `influx:"humidity"`
ID string `influx:"-"`
}
samplesRead := []EnvSample{}
q := `SELECT * FROM test ORDER BY time DESC LIMIT 10`
c.UseDB("myDb").DecodeQuery(q, &samplesRead)
// samplesRead is now populated with data from InfluxDb
}