forked from asonawalla/gazette
/
properties.go
38 lines (32 loc) · 1.07 KB
/
properties.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
package cloudstore
import "fmt"
// Properties gets values for keys, and allows a Filesytem to configure itself.
type Properties interface {
Get(string) string
}
// EmptyProperties returns an empty set of properties, useful for callers who
// don't need to specify any additional connection parameters when initializing
// a FileSystem.
func EmptyProperties() Properties {
return make(MapProperties)
}
// MapProperties is a simple implementation of Properties backed by an in-memory map.
type MapProperties map[string]string
// Get satisfies the |Properties| interface.
func (mp MapProperties) Get(key string) string {
return mp[key]
}
// mergeProperties only works when both |a| and |b| are MapProperties. merges
// the values from |a| onto |b|.
func mergeProperties(a, b Properties) (Properties, error) {
if src, ok := a.(MapProperties); !ok {
return nil, fmt.Errorf("%v is not a MapProperties", a)
} else if dest, ok := b.(MapProperties); !ok {
return nil, fmt.Errorf("%v is not a MapProperties", b)
} else {
for k, v := range src {
dest[k] = v
}
return dest, nil
}
}