-
Notifications
You must be signed in to change notification settings - Fork 6
/
env.go
45 lines (39 loc) · 1.01 KB
/
env.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
// Package cfg :: env.go
package cfg
// Env struct stores application-wide configuration
type Env map[string]interface{}
// Delete removes a key and the mapping value
func (env Env) Delete(key string) {
delete(env, key)
}
// Get returns string for the mapping value by the key
func (env Env) Get(key string) string {
if val := env.GetValue(key); val != nil {
if strValue, ok := val.(string); ok {
return strValue
}
}
//TODO [jzhu]: considering to return a string representation by
//e.g. fmt.Sprintf("%+v", val)
return ""
}
// GetInt returns int for the mapping value by the key
func (env Env) GetInt(key string) int {
if val := env.GetValue(key); val != nil {
if intValue, ok := val.(int); ok {
return intValue
}
}
return 0
}
// GetValue returns the mapping value by the key
func (env Env) GetValue(key string) interface{} {
if val, ok := env[key]; ok {
return val
}
return nil
}
// Set overwrite the mapping value by the key
func (env Env) Set(key string, value interface{}) {
env[key] = value
}