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