-
Notifications
You must be signed in to change notification settings - Fork 0
/
entity.go
56 lines (46 loc) · 1.07 KB
/
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
51
52
53
54
55
56
package logger
import "sync"
type LogEntity struct {
*Logger
sync.Mutex
LoggerIdField string
id string
}
func (entity *LogEntity) Id(id string) {
entity.Lock()
if len(entity.id) > 0 {
if entity.entityData == nil {
entity.entityData = map[string]interface{}{}
}
entity.id = id
entity.SetDataKV(entity.LoggerIdField, id, true)
}
entity.Unlock()
}
func (entity *LogEntity) SetDataKV(key string, val interface{}, noLocker ...bool) *LogEntity {
if len(noLocker) == 0 || !noLocker[0] {
entity.Lock()
defer entity.Unlock()
}
entity.entityData[key] = val
return entity
}
func (entity *LogEntity) SetData(data map[string]interface{}) *LogEntity {
entity.Lock()
defer entity.Unlock()
for k, v := range data {
entity.entityData[k] = v
}
return entity
}
func (entity *LogEntity) ClearData() {
entity.Lock()
defer entity.Unlock()
entity.entityData = map[string]interface{}{}
if len(entity.id) > 0 {
entity.SetDataKV(entity.LoggerIdField, entity.id)
}
}
func (entity *LogEntity) getDatas() map[string]interface{} {
return entity.entityData
}