-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.internal.go
75 lines (62 loc) · 1.31 KB
/
source.internal.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
70
71
72
73
74
75
package dyanmic_params
import "regexp"
const SrcNameInternal = "source.internal"
type internalParamCollection map[string]interface{}
type SourceInternal struct {
storage internalParamCollection
}
func NewSourceInternal() *SourceInternal {
return &SourceInternal{
storage: make(internalParamCollection, 0),
}
}
func (s *SourceInternal) Add(name string, value interface{}) ParamsSource {
s.storage[name] = value
return s
}
func (s *SourceInternal) Get(name string) interface{} {
if s.storage == nil {
return ""
} else if val, ok := s.storage[name]; ok {
return val
}
return nil
}
func (s *SourceInternal) Scan(regex string) map[string]interface{} {
if s.Count() > 0 {
mp := make(map[string]interface{}, 0)
rg, err := regexp.Compile(regex)
if err != nil {
return nil
}
for k, v := range s.storage {
if rg.MatchString(k) {
mp[k] = v
}
}
return mp
}
return nil
}
func (s *SourceInternal) Iterate(fn func(k string, v interface{})) {
if s.Count() > 0 {
for k, v := range s.storage {
fn(k, v)
}
}
return
}
func (s *SourceInternal) Has(name string) bool {
if s.storage == nil {
return false
} else if _, ok := s.storage[name]; ok {
return true
}
return false
}
func (s *SourceInternal) Count() int64 {
if s.storage == nil {
return 0
}
return int64(len(s.storage))
}