envconf/main.go

33 lines
669 B
Go
Raw Normal View History

2021-03-23 09:13:25 +00:00
package envconf
2021-03-23 08:48:02 +00:00
2021-03-23 09:13:25 +00:00
import ("fmt"
2021-03-23 08:48:02 +00:00
"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)
config.env = make(map[string]string)
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
env[key] = val
2021-03-23 08:48:02 +00:00
}
}
2021-03-23 09:13:25 +00:00
fmt.Println(config)
2021-03-23 08:48:02 +00:00
}