-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.go
54 lines (49 loc) · 1.15 KB
/
config.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
package main
import "strings"
// Config for fillin
type Config struct {
Scopes map[string]*Scope `json:"scopes"`
}
// Scope holds pairs of values
type Scope struct {
Values []map[string]string `json:"values"`
}
func (config *Config) collectHistory(id *Identifier) []string {
values := []string{}
added := make(map[string]bool)
if _, ok := config.Scopes[id.scope]; ok {
for _, value := range config.Scopes[id.scope].Values {
if v, ok := value[id.key]; ok && !added[v] {
values = append(values, v)
added[v] = true
}
}
}
return values
}
func (config *Config) collectScopedPairHistory(idg *IdentifierGroup) []string {
values := []string{}
added := make(map[string]bool)
if _, ok := config.Scopes[idg.scope]; ok {
for _, value := range config.Scopes[idg.scope].Values {
contained := true
var vs []string
for _, key := range idg.keys {
if v, ok := value[key]; ok {
vs = append(vs, strings.Replace(v, ", ", ",\\ ", -1))
} else {
contained = false
break
}
}
if contained {
v := strings.Join(vs, ", ")
if !added[v] {
values = append(values, v)
added[v] = true
}
}
}
}
return values
}