-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.go
52 lines (42 loc) · 800 Bytes
/
data.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
package harvester
type Seeds map[MetadataKey]string
func (s Seeds) ToData() Data {
result := make(Data, len(s))
for k, v := range s {
result.Add(k, v, "seed")
}
return result
}
type Data map[MetadataKey][]*Metadata
func (d Data) Count() int {
count := 0
for _, metas := range d {
for range metas {
count++
}
}
return count
}
func (d Data) ForEach(k MetadataKey, f func(m *Metadata) error) error {
for _, meta := range d[k] {
if err := f(meta); err != nil {
return err
}
}
return nil
}
func (d Data) Add(k MetadataKey, v string, pitchfork string) {
if v != "" {
if _, ok := d[k]; ok {
for _, metadata := range d[k] {
if metadata.Value == v {
return
}
}
}
d[k] = append(d[k], &Metadata{
Value: v,
Pitchfork: pitchfork,
})
}
}