upper env

This commit is contained in:
Roy Olav Purser 2021-03-23 19:44:53 +01:00
parent 67ba140c7e
commit 4bfee731fe
No known key found for this signature in database
GPG Key ID: 0BA77797F072BC52

24
main.go
View File

@ -26,7 +26,7 @@ func NewConfig()(*Config) {
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.TrimSpace(strings.ToLower(splitted[0])) key := strings.TrimSpace(strings.ToUpper(splitted[0]))
if unicode.IsLetter(getFirstRune(key)) { if unicode.IsLetter(getFirstRune(key)) {
var entry cEntry var entry cEntry
entry.value = splitted[1] entry.value = splitted[1]
@ -41,7 +41,8 @@ func NewConfig()(*Config) {
} }
func (c *Config) Define(key string, dtype DataType) { func (c *Config) Define(key string, dtype DataType) {
entry, ok := c.env[key] upper := strings.ToUpper(key)
entry, ok := c.env[upper]
if ok { if ok {
entry.dtype = dtype entry.dtype = dtype
} else { } else {
@ -49,12 +50,13 @@ func (c *Config) Define(key string, dtype DataType) {
entry.dtype = dtype entry.dtype = dtype
entry.unset = true entry.unset = true
entry.empty = true entry.empty = true
c.env[key] = entry c.env[upper] = entry
} }
} }
func (c *Config) DefineDefault(key string, val string, dtype DataType) { func (c *Config) DefineDefault(key string, val string, dtype DataType) {
entry, ok := c.env[key] upper := strings.ToUpper(key)
entry, ok := c.env[upper]
if ok { if ok {
if entry.unset { if entry.unset {
entry.empty = false entry.empty = false
@ -66,7 +68,7 @@ func (c *Config) DefineDefault(key string, val string, dtype DataType) {
entry.dtype = dtype entry.dtype = dtype
entry.unset = true entry.unset = true
entry.empty = false entry.empty = false
c.env[key] = entry c.env[upper] = entry
} }
} }
@ -101,7 +103,8 @@ func (c *Config) Status()(ok bool) {
func (c *Config) GetInt(key string)(int64) { func (c *Config) GetInt(key string)(int64) {
if c.parsed { if c.parsed {
entry, ok := c.env[key] upper := strings.ToUpper(key)
entry, ok := c.env[upper]
if ok { if ok {
return entry.parsed.intval return entry.parsed.intval
} }
@ -110,7 +113,8 @@ func (c *Config) GetInt(key string)(int64) {
} }
func (c *Config) GetString(key string)(string) { func (c *Config) GetString(key string)(string) {
if c.parsed { if c.parsed {
entry, ok := c.env[key] upper := strings.ToUpper(key)
entry, ok := c.env[upper]
if ok { if ok {
return entry.parsed.strval return entry.parsed.strval
} }
@ -119,7 +123,8 @@ func (c *Config) GetString(key string)(string) {
} }
func (c *Config) GetDuration(key string)(time.Duration) { func (c *Config) GetDuration(key string)(time.Duration) {
if c.parsed { if c.parsed {
entry, ok := c.env[key] upper := strings.ToUpper(key)
entry, ok := c.env[upper]
if ok { if ok {
return entry.parsed.durval return entry.parsed.durval
} }
@ -128,7 +133,8 @@ func (c *Config) GetDuration(key string)(time.Duration) {
} }
func (c *Config) GetBool(key string)(bool) { func (c *Config) GetBool(key string)(bool) {
if c.parsed { if c.parsed {
entry, ok := c.env[key] upper := strings.ToUpper(key)
entry, ok := c.env[upper]
if ok { if ok {
return entry.parsed.boolval return entry.parsed.boolval
} }