env has to start with letter

This commit is contained in:
Roy Olav Purser 2021-03-23 11:08:26 +01:00
parent 341c50b756
commit 55326ef470
No known key found for this signature in database
GPG Key ID: 0BA77797F072BC52

20
main.go
View File

@ -1,6 +1,7 @@
package envconf
import ("strings"
"unicode"
"os")
const TypeNone = (1 << 1)
@ -13,17 +14,26 @@ type Config struct {
}
func getFirstRune(str string)(rune) {
for _,v := range str {
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.ToLower(splitted[0])
strval := splitted[1]
val := make(map[string]int)
val[strval] = TypeNone
config.env[key] = val
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