2016-08-03 23:42:21 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
// mapFetcher provides an implementation of the Fetcher interface by wrapping
|
|
|
|
// the `map[string]string` type.
|
|
|
|
type mapFetcher map[string]string
|
|
|
|
|
2016-08-05 00:58:43 +00:00
|
|
|
func MapFetcher(m map[string]string) Fetcher {
|
|
|
|
return mapFetcher(m)
|
|
|
|
}
|
|
|
|
|
2016-08-03 23:42:21 +00:00
|
|
|
// Get implements the func `Fetcher.Get`.
|
2016-08-05 21:59:57 +00:00
|
|
|
func (m mapFetcher) Get(key string) (val string, ok bool) {
|
|
|
|
val, ok = m[key]
|
|
|
|
return
|
|
|
|
}
|
2016-11-10 00:33:43 +00:00
|
|
|
|
|
|
|
func (m mapFetcher) All() map[string]string {
|
|
|
|
newmap := make(map[string]string)
|
|
|
|
for key, value := range m {
|
|
|
|
newmap[key] = value
|
|
|
|
}
|
|
|
|
return newmap
|
|
|
|
}
|
2016-11-10 00:37:14 +00:00
|
|
|
|
2016-11-10 18:16:46 +00:00
|
|
|
func (m mapFetcher) set(key, value string) {
|
2016-11-10 00:46:52 +00:00
|
|
|
m[key] = value
|
|
|
|
}
|
|
|
|
|
2016-11-10 18:16:46 +00:00
|
|
|
func (m mapFetcher) del(key string) {
|
2016-11-10 00:37:14 +00:00
|
|
|
delete(m, key)
|
|
|
|
}
|