-
Notifications
You must be signed in to change notification settings - Fork 4
/
datamodel.go
59 lines (48 loc) · 1.15 KB
/
datamodel.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
package common
// DataModel defined standard data model for transferring data between interfaces
type DataModel struct {
// TODO DataModel is standardized data, need add field
DeviceName string
PropertyName string
Namespace string
Value string
Type string
TimeStamp int64
}
type Option func(*DataModel)
func (dm *DataModel) SetType(dataType string) {
dm.Type = dataType
}
func (dm *DataModel) SetValue(data string) {
dm.Value = data
}
func (dm *DataModel) SetTimeStamp() {
dm.TimeStamp = getTimestamp()
}
func WithType(dataType string) Option {
return func(model *DataModel) {
model.Type = dataType
}
}
func WithValue(data string) Option {
return func(model *DataModel) {
model.Value = data
}
}
func WithTimeStamp(timeStamp int64) Option {
return func(model *DataModel) {
model.TimeStamp = timeStamp
}
}
func NewDataModel(deviceName string, propertyName string, namespace string, options ...Option) *DataModel {
dataModel := &DataModel{
DeviceName: deviceName,
PropertyName: propertyName,
Namespace: namespace,
TimeStamp: getTimestamp(),
}
for _, option := range options {
option(dataModel)
}
return dataModel
}