Debian Codegraph @

config/map_fetcher.go

raw symbols SCIP
1 package config
2
3 // mapFetcher provides an implementation of the Fetcher interface by wrapping
4 // the `map[string]string` type.
5 type mapFetcher map[string][]string
6
7 func UniqMapFetcher(m map[string]string) Fetcher {
8 multi := make(map[string][]string, len(m))
9 for k, v := range m {
10 multi[k] = []string{v}
11 }
12
13 return MapFetcher(multi)
14 }
15
16 func MapFetcher(m map[string][]string) Fetcher {
17 return mapFetcher(m)
18 }
19
20 // Get implements the func `Fetcher.Get`.
21 func (m mapFetcher) Get(key string) (val string, ok bool) {
22 all := m.GetAll(key)
23
24 if len(all) == 0 {
25 return "", false
26 }
27 return all[len(all)-1], true
28 }
29
30 // Get implements the func `Fetcher.GetAll`.
31 func (m mapFetcher) GetAll(key string) []string {
32 return m[key]
33 }
34
35 func (m mapFetcher) All() map[string][]string {
36 newmap := make(map[string][]string)
37 for key, values := range m {
38 for _, value := range values {
39 newmap[key] = append(newmap[key], value)
40 }
41 }
42 return newmap
43 }