what a rabbithole. lots of goodies now.
This commit is contained in:
60
envs/.TODO.go.UNFINISHED
Normal file
60
envs/.TODO.go.UNFINISHED
Normal file
@@ -0,0 +1,60 @@
|
||||
package envs
|
||||
|
||||
/*
|
||||
EnvMapper contains the environment variables as grouped by their basic type.
|
||||
If a variable's type cannot be determined, it's placed in Strings.
|
||||
If a variable's type is a list, it will be an []interface{} as each item may be a different variable type.
|
||||
It essentially is the same as EnvMap except with the types split out for convenience.
|
||||
*/
|
||||
type EnvMapper struct {
|
||||
Booleans map[string]bool `json:"bools"`
|
||||
Numbers map[string]int `json:"nums"`
|
||||
Strings map[string]string `json:"strings"`
|
||||
Lists map[string][]interface{} `json:"lists"`
|
||||
}
|
||||
|
||||
// GetEnvMapper returns a pointer to a populated EnvMapper.
|
||||
func GetEnvMapper() (e *EnvMapper, err error) {
|
||||
|
||||
var em map[string]interface{}
|
||||
var env EnvMapper
|
||||
|
||||
env = EnvMapper{
|
||||
Booleans: nil,
|
||||
Numbers: nil,
|
||||
Strings: nil,
|
||||
Lists: nil,
|
||||
}
|
||||
|
||||
for k, v := range em {
|
||||
|
||||
switch t := v.(type) {
|
||||
case bool:
|
||||
if env.Booleans == nil {
|
||||
env.Booleans = make(map[string]bool, 0)
|
||||
}
|
||||
env.Booleans[k] = t
|
||||
continue
|
||||
case int:
|
||||
if env.Numbers == nil {
|
||||
env.Numbers = make(map[string]int, 0)
|
||||
}
|
||||
env.Numbers[k] = t
|
||||
continue
|
||||
case []interface{}:
|
||||
if env.Lists == nil {
|
||||
env.Lists = make(map[string][]interface{}, 0)
|
||||
}
|
||||
env.Lists[k] = t
|
||||
case string: // the "default" since everything could probably be typeswitched to a string otherwise.
|
||||
if env.Strings == nil {
|
||||
env.Strings = make(map[string]string, 0)
|
||||
}
|
||||
env.Strings[k] = t
|
||||
}
|
||||
}
|
||||
|
||||
*e = env
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user