forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_fetcher.go
43 lines (35 loc) · 943 Bytes
/
map_fetcher.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
package config
// mapFetcher provides an implementation of the Fetcher interface by wrapping
// the `map[string]string` type.
type mapFetcher map[string][]string
func UniqMapFetcher(m map[string]string) Fetcher {
multi := make(map[string][]string, len(m))
for k, v := range m {
multi[k] = []string{v}
}
return MapFetcher(multi)
}
func MapFetcher(m map[string][]string) Fetcher {
return mapFetcher(m)
}
// Get implements the func `Fetcher.Get`.
func (m mapFetcher) Get(key string) (val string, ok bool) {
all := m.GetAll(key)
if len(all) == 0 {
return "", false
}
return all[len(all)-1], true
}
// Get implements the func `Fetcher.GetAll`.
func (m mapFetcher) GetAll(key string) []string {
return m[key]
}
func (m mapFetcher) All() map[string][]string {
newmap := make(map[string][]string)
for key, values := range m {
for _, value := range values {
newmap[key] = append(newmap[key], value)
}
}
return newmap
}