envconf/main.go
2021-03-23 11:14:30 +01:00

43 lines
954 B
Go

package envconf
import ("strings"
"unicode"
"fmt"
"os")
const TypeNone = (1 << 1)
const TypeInt = (1 << 2)
const TypeDuration = (1 << 3)
const TypeString = (1 << 4)
type Config struct {
env map[string]map[string]int
}
func getFirstRune(str string)(rune) {
for _,v := range str {
fmt.Printf("symbol (%c) (%d)\n", v, v)
return v
}
return rune(0)
}
func NewConfig()(*Config) {
config := new(Config)
config.env = make(map[string]map[string]int)
for _,v := range os.Environ() {
splitted := strings.SplitN(v, "=", 2)
if len(splitted) == 2 {
key := strings.TrimSpace(strings.ToLower(splitted[0]))
if unicode.IsLetter(getFirstRune(key)) {
strval := splitted[1]
val := make(map[string]int)
val[strval] = TypeNone
config.env[key] = val
}
}
}
return config
}