forked from cbrake/influxdbhelper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.go
38 lines (31 loc) · 736 Bytes
/
tag.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
package influxdbhelper
import (
"strings"
)
// Measurement is a type that defines the influx db measurement.
type Measurement = string
type influxFieldTagData struct {
fieldName string
isTag bool
isField bool
}
func getInfluxFieldTagData(fieldName, structTag string) (fieldData *influxFieldTagData) {
fieldData = &influxFieldTagData{fieldName: fieldName}
parts := strings.Split(structTag, ",")
fieldName, parts = parts[0], parts[1:]
if fieldName != "" {
fieldData.fieldName = fieldName
}
for _, part := range parts {
if part == "tag" {
fieldData.isTag = true
}
if part == "field" {
fieldData.isField = true
}
}
if !fieldData.isField && !fieldData.isTag {
fieldData.isField = true
}
return
}