2021-03-23 09:13:25 +00:00
|
|
|
package envconf
|
2021-03-23 08:48:02 +00:00
|
|
|
|
2021-03-23 09:28:16 +00:00
|
|
|
import ("strings"
|
2021-03-23 09:13:25 +00:00
|
|
|
"os")
|
2021-03-23 08:48:02 +00:00
|
|
|
|
2021-03-23 09:13:25 +00:00
|
|
|
const TypeNone = (1 << 1)
|
|
|
|
const TypeInt = (1 << 2)
|
|
|
|
const TypeDuration = (1 << 3)
|
|
|
|
const TypeString = (1 << 4)
|
2021-03-23 08:48:02 +00:00
|
|
|
|
|
|
|
type Config struct {
|
2021-03-23 09:13:25 +00:00
|
|
|
env map[string]map[string]int
|
2021-03-23 08:48:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-03-23 09:13:25 +00:00
|
|
|
func NewConfig()(*Config) {
|
|
|
|
config := new(Config)
|
2021-03-23 09:16:25 +00:00
|
|
|
config.env = make(map[string]map[string]int)
|
2021-03-23 09:13:25 +00:00
|
|
|
for _,v := range os.Environ() {
|
|
|
|
splitted := strings.SplitN(v, "=", 2)
|
|
|
|
if len(splitted) == 2 {
|
|
|
|
key := strings.ToLower(splitted[0])
|
|
|
|
strval := splitted[1]
|
|
|
|
val := make(map[string]int)
|
|
|
|
val[strval] = TypeNone
|
2021-03-23 09:26:51 +00:00
|
|
|
config.env[key] = val
|
2021-03-23 08:48:02 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-23 09:26:51 +00:00
|
|
|
return config
|
2021-03-23 08:48:02 +00:00
|
|
|
}
|
|
|
|
|