env has to start with letter
This commit is contained in:
parent
341c50b756
commit
55326ef470
20
main.go
20
main.go
@ -1,6 +1,7 @@
|
|||||||
package envconf
|
package envconf
|
||||||
|
|
||||||
import ("strings"
|
import ("strings"
|
||||||
|
"unicode"
|
||||||
"os")
|
"os")
|
||||||
|
|
||||||
const TypeNone = (1 << 1)
|
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) {
|
func NewConfig()(*Config) {
|
||||||
config := new(Config)
|
config := new(Config)
|
||||||
config.env = make(map[string]map[string]int)
|
config.env = make(map[string]map[string]int)
|
||||||
for _,v := range os.Environ() {
|
for _,v := range os.Environ() {
|
||||||
splitted := strings.SplitN(v, "=", 2)
|
splitted := strings.SplitN(v, "=", 2)
|
||||||
if len(splitted) == 2 {
|
if len(splitted) == 2 {
|
||||||
key := strings.ToLower(splitted[0])
|
key := strings.TrimSpace(strings.ToLower(splitted[0]))
|
||||||
strval := splitted[1]
|
if unicode.IsLetter(getFirstRune(key)) {
|
||||||
val := make(map[string]int)
|
strval := splitted[1]
|
||||||
val[strval] = TypeNone
|
val := make(map[string]int)
|
||||||
config.env[key] = val
|
val[strval] = TypeNone
|
||||||
|
config.env[key] = val
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
|
Loading…
x
Reference in New Issue
Block a user