forked from bitmagnet-io/bitmagnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.go
109 lines (97 loc) · 2.56 KB
/
source.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package classifier
type Source struct {
Schema string `json:"$schema,omitempty" yaml:"$schema,omitempty"`
Workflows workflowSources `json:"workflows"`
FlagDefinitions flagDefinitions `json:"flag_definitions"`
Flags Flags `json:"flags"`
Keywords keywordGroups `json:"keywords"`
Extensions extensionGroups `json:"extensions"`
Plugins pluginGroups `json:"plugins,omitempty"`
}
func (s Source) merge(other Source) (Source, error) {
flagDefs, err := s.FlagDefinitions.merge(other.FlagDefinitions)
if err != nil {
return Source{}, err
}
return Source{
FlagDefinitions: flagDefs,
Flags: s.Flags.merge(other.Flags),
Keywords: s.Keywords.merge(other.Keywords),
Extensions: s.Extensions.merge(other.Extensions),
Workflows: s.Workflows.merge(other.Workflows),
Plugins: s.Plugins.merge(other.Plugins),
}, nil
}
func (s Source) workflowNames() map[string]struct{} {
result := make(map[string]struct{})
for k := range s.Workflows {
result[k] = struct{}{}
}
return result
}
type keywordGroups map[string][]string
func (g keywordGroups) merge(other keywordGroups) keywordGroups {
result := make(keywordGroups)
for k, v := range g {
if _, ok := other[k]; ok {
result[k] = append(v, other[k]...)
} else {
result[k] = v
}
}
for k, v := range other {
if _, ok := result[k]; !ok {
result[k] = v
}
}
return result
}
type extensionGroups map[string][]string
func (g extensionGroups) merge(other extensionGroups) extensionGroups {
result := make(extensionGroups)
for k, v := range g {
if _, ok := other[k]; ok {
result[k] = append(v, other[k]...)
} else {
result[k] = v
}
}
for k, v := range other {
if _, ok := result[k]; !ok {
result[k] = v
}
}
return result
}
type workflowSources map[string]any
func (s workflowSources) merge(other workflowSources) workflowSources {
result := make(workflowSources)
for k, v := range s {
result[k] = v
}
for k, v := range other {
result[k] = v
}
return result
}
type pluginSource struct {
Url string `json:"url"`
ApiKey *string `json:"apikey,omitempty"`
Start *string `json:"start,omitempy"`
End *string `json:"end,omitempy"`
Days *int `json:"days,omitempty"`
}
type pluginGroups []struct {
Source pluginSource `json:"source"`
Flag string `json:"flag"`
}
func (s pluginGroups) merge(other pluginGroups) pluginGroups {
var result pluginGroups
for _, v := range s {
result = append(result, v)
}
for _, v := range other {
result = append(result, v)
}
return result
}