-
Notifications
You must be signed in to change notification settings - Fork 3
/
influx_qu.go
69 lines (55 loc) · 1.37 KB
/
influx_qu.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package influxqu
import (
"github.com/influxdata/influxdb-client-go/v2/api/write"
)
type InfluxQu interface {
GenerateInfluxPoint(val interface{}) (*write.Point, error)
GenerateFluxQuery(bucket, start, end string, val interface{}, suffix []string) (query string, cols []string, err error)
}
const (
omitemptyKey = "omitempty"
)
type influxQu struct {
key string
measurementKey string
fieldKey string
tagKey string
timestampKey string
}
func NewinfluxQu() InfluxQu {
i, _ := NewinfluxQuWithKeys("influxqu", "measurement", "tag", "field", "timestamp")
return i
}
func NewinfluxQuWithKeys(key string, measurementKey string, tagKey string, fieldKey string, timestampKey string) (InfluxQu, error) {
if key == "" {
key = "influxqu"
}
if measurementKey == "" {
measurementKey = "measurement"
}
if fieldKey == "" {
fieldKey = "field"
}
if tagKey == "" {
tagKey = "tag"
}
if timestampKey == "" {
timestampKey = "timestamp"
}
keys := make(map[string]struct{}, 5)
keys[key] = struct{}{}
keys[measurementKey] = struct{}{}
keys[fieldKey] = struct{}{}
keys[tagKey] = struct{}{}
keys[timestampKey] = struct{}{}
if len(keys) != 5 {
return nil, &DuplicatedKey{}
}
return &influxQu{
key: key,
measurementKey: measurementKey,
fieldKey: fieldKey,
tagKey: tagKey,
timestampKey: timestampKey,
}, nil
}