-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.go
50 lines (41 loc) · 928 Bytes
/
entity.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
package data
import (
"encoding/json"
"time"
)
const (
DefaultStep int = 60
)
type Entity struct {
Endpoint string `json:"endpoint"`
Tags string `json:"tags"`
Metric string `json:"metric"`
Value float64 `json:"value"`
CounterType string `json:"counterType"`
Timestamp int64 `json:"timestamp"`
Step int `json:"step"`
}
func NewEntity(endpoint, tags, metric string) *Entity {
now := time.Now().Unix()
return &Entity{
Endpoint: endpoint,
Tags: tags,
Metric: metric,
Timestamp: now,
Step: DefaultStep,
}
}
func (entity *Entity) SetValueAndType(value float64, counterType CounterType) {
entity.Value = value
entity.CounterType = counterType.String()
}
func (entity *Entity) SetStep(step int) {
entity.Step = step
}
func (entity *Entity) String() string {
ret, err := json.Marshal(&entity)
if err != nil {
return ""
}
return string(ret)
}