-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmetadata.go
54 lines (44 loc) · 864 Bytes
/
metadata.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 courier
import (
"net/url"
)
// merge metadata into one MetaData
func FromMetas(metas ...Metadata) Metadata {
m := Metadata{}
for _, meta := range metas {
m.Merge(meta)
}
return m
}
type Metadata map[string][]string
func (m Metadata) String() string {
return url.Values(m).Encode()
}
func (m Metadata) Del(key string) {
delete(m, key)
}
func (m Metadata) Merge(metadata Metadata) {
for key, values := range metadata {
m.Set(key, values...)
}
}
func (m Metadata) Add(key, value string) {
if values, ok := m[key]; ok {
m[key] = append(values, value)
} else {
m.Set(key, value)
}
}
func (m Metadata) Set(key string, values ...string) {
m[key] = values
}
func (m Metadata) Has(key string) bool {
_, ok := m[key]
return ok
}
func (m Metadata) Get(key string) string {
if v := m[key]; len(v) > 0 {
return v[0]
}
return ""
}