Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
b901036467 | |||
eef48c1d0a | |||
27d793492c | |||
4a84dcdabe | |||
9badf9a54a | |||
62ff297952 | |||
6fea990cb9 | |||
19fdcd7e05 | |||
7a72947737 | |||
3c23ee5473 | |||
4520530b7f | |||
113ff46fee | |||
5262d7abb7 | |||
2efc1a155e | |||
45f8b0f918 | |||
2cdcbec364 | |||
f815bff582 | |||
73278439b0 | |||
0a589a2565 | |||
179666c8f9 | |||
02d36e3d69 | |||
9733bb42a8 | |||
3d2005a8a2 | |||
1803501272 | |||
d1bcc8c4cc | |||
afa50b4fca |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tests/buildenv/*
|
||||||
|
tests/bin/*
|
@ -1,3 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
go fmt *.go
|
go fmt *.go
|
||||||
git add *.go
|
go fmt tests/*.go
|
||||||
|
|
||||||
|
git add *.go tests/*.go
|
||||||
|
git add tests/*.go
|
||||||
|
916
auto_generated.go
Normal file
916
auto_generated.go
Normal file
@ -0,0 +1,916 @@
|
|||||||
|
package envconf
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type mapEnvType [5]*keyLookupType
|
||||||
|
|
||||||
|
func (c *Config) GetMapInt(key string) (empty map[string]int64) {
|
||||||
|
empty = make(map[string]int64)
|
||||||
|
retval := make(map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[0].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
entry := c.env[v11.key]
|
||||||
|
if (entry.dtype.baseType() == TypeInt.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMetric(key string) (empty map[string]int64) {
|
||||||
|
empty = make(map[string]int64)
|
||||||
|
retval := make(map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[0].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
entry := c.env[v11.key]
|
||||||
|
if (entry.dtype.baseType() == TypeMetric.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapDuration(key string) (empty map[string]time.Duration) {
|
||||||
|
empty = make(map[string]time.Duration)
|
||||||
|
retval := make(map[string]time.Duration)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[0].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
entry := c.env[v11.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDuration.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11] = entry.parsed.durval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapString(key string) (empty map[string]string) {
|
||||||
|
empty = make(map[string]string)
|
||||||
|
retval := make(map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[0].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
entry := c.env[v11.key]
|
||||||
|
if (entry.dtype.baseType() == TypeString.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapDirectory(key string) (empty map[string]string) {
|
||||||
|
empty = make(map[string]string)
|
||||||
|
retval := make(map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[0].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
entry := c.env[v11.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDirectory.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapBool(key string) (empty map[string]bool) {
|
||||||
|
empty = make(map[string]bool)
|
||||||
|
retval := make(map[string]bool)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[0].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
entry := c.env[v11.key]
|
||||||
|
if (entry.dtype.baseType() == TypeBool.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11] = entry.parsed.boolval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapHex(key string) (empty map[string][]byte) {
|
||||||
|
empty = make(map[string][]byte)
|
||||||
|
retval := make(map[string][]byte)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[0].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
entry := c.env[v11.key]
|
||||||
|
if (entry.dtype.baseType() == TypeHex.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11] = entry.parsed.binval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapInt(key string) (empty map[string]map[string]int64) {
|
||||||
|
empty = make(map[string]map[string]int64)
|
||||||
|
retval := make(map[string]map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[1].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]int64)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
entry := c.env[v12.key]
|
||||||
|
if (entry.dtype.baseType() == TypeInt.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMetric(key string) (empty map[string]map[string]int64) {
|
||||||
|
empty = make(map[string]map[string]int64)
|
||||||
|
retval := make(map[string]map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[1].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]int64)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
entry := c.env[v12.key]
|
||||||
|
if (entry.dtype.baseType() == TypeMetric.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapDuration(key string) (empty map[string]map[string]time.Duration) {
|
||||||
|
empty = make(map[string]map[string]time.Duration)
|
||||||
|
retval := make(map[string]map[string]time.Duration)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[1].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]time.Duration)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
entry := c.env[v12.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDuration.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12] = entry.parsed.durval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapString(key string) (empty map[string]map[string]string) {
|
||||||
|
empty = make(map[string]map[string]string)
|
||||||
|
retval := make(map[string]map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[1].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]string)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
entry := c.env[v12.key]
|
||||||
|
if (entry.dtype.baseType() == TypeString.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapDirectory(key string) (empty map[string]map[string]string) {
|
||||||
|
empty = make(map[string]map[string]string)
|
||||||
|
retval := make(map[string]map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[1].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]string)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
entry := c.env[v12.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDirectory.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapBool(key string) (empty map[string]map[string]bool) {
|
||||||
|
empty = make(map[string]map[string]bool)
|
||||||
|
retval := make(map[string]map[string]bool)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[1].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]bool)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
entry := c.env[v12.key]
|
||||||
|
if (entry.dtype.baseType() == TypeBool.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12] = entry.parsed.boolval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapHex(key string) (empty map[string]map[string][]byte) {
|
||||||
|
empty = make(map[string]map[string][]byte)
|
||||||
|
retval := make(map[string]map[string][]byte)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[1].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string][]byte)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
entry := c.env[v12.key]
|
||||||
|
if (entry.dtype.baseType() == TypeHex.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12] = entry.parsed.binval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapInt(key string) (empty map[string]map[string]map[string]int64) {
|
||||||
|
empty = make(map[string]map[string]map[string]int64)
|
||||||
|
retval := make(map[string]map[string]map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[2].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]int64)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]int64)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
entry := c.env[v13.key]
|
||||||
|
if (entry.dtype.baseType() == TypeInt.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMetric(key string) (empty map[string]map[string]map[string]int64) {
|
||||||
|
empty = make(map[string]map[string]map[string]int64)
|
||||||
|
retval := make(map[string]map[string]map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[2].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]int64)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]int64)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
entry := c.env[v13.key]
|
||||||
|
if (entry.dtype.baseType() == TypeMetric.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapDuration(key string) (empty map[string]map[string]map[string]time.Duration) {
|
||||||
|
empty = make(map[string]map[string]map[string]time.Duration)
|
||||||
|
retval := make(map[string]map[string]map[string]time.Duration)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[2].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]time.Duration)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]time.Duration)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
entry := c.env[v13.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDuration.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13] = entry.parsed.durval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapString(key string) (empty map[string]map[string]map[string]string) {
|
||||||
|
empty = make(map[string]map[string]map[string]string)
|
||||||
|
retval := make(map[string]map[string]map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[2].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]string)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]string)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
entry := c.env[v13.key]
|
||||||
|
if (entry.dtype.baseType() == TypeString.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapDirectory(key string) (empty map[string]map[string]map[string]string) {
|
||||||
|
empty = make(map[string]map[string]map[string]string)
|
||||||
|
retval := make(map[string]map[string]map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[2].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]string)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]string)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
entry := c.env[v13.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDirectory.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapBool(key string) (empty map[string]map[string]map[string]bool) {
|
||||||
|
empty = make(map[string]map[string]map[string]bool)
|
||||||
|
retval := make(map[string]map[string]map[string]bool)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[2].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]bool)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]bool)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
entry := c.env[v13.key]
|
||||||
|
if (entry.dtype.baseType() == TypeBool.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13] = entry.parsed.boolval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapHex(key string) (empty map[string]map[string]map[string][]byte) {
|
||||||
|
empty = make(map[string]map[string]map[string][]byte)
|
||||||
|
retval := make(map[string]map[string]map[string][]byte)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[2].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string][]byte)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string][]byte)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
entry := c.env[v13.key]
|
||||||
|
if (entry.dtype.baseType() == TypeHex.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13] = entry.parsed.binval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapInt(key string) (empty map[string]map[string]map[string]map[string]int64) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]int64)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[3].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]int64)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]int64)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]int64)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
entry := c.env[v14.key]
|
||||||
|
if (entry.dtype.baseType() == TypeInt.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapMetric(key string) (empty map[string]map[string]map[string]map[string]int64) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]int64)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[3].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]int64)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]int64)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]int64)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
entry := c.env[v14.key]
|
||||||
|
if (entry.dtype.baseType() == TypeMetric.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapDuration(key string) (empty map[string]map[string]map[string]map[string]time.Duration) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]time.Duration)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]time.Duration)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[3].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]time.Duration)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]time.Duration)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]time.Duration)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
entry := c.env[v14.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDuration.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14] = entry.parsed.durval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapString(key string) (empty map[string]map[string]map[string]map[string]string) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]string)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[3].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]string)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]string)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]string)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
entry := c.env[v14.key]
|
||||||
|
if (entry.dtype.baseType() == TypeString.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapDirectory(key string) (empty map[string]map[string]map[string]map[string]string) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]string)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[3].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]string)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]string)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]string)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
entry := c.env[v14.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDirectory.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapBool(key string) (empty map[string]map[string]map[string]map[string]bool) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]bool)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]bool)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[3].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]bool)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]bool)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]bool)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
entry := c.env[v14.key]
|
||||||
|
if (entry.dtype.baseType() == TypeBool.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14] = entry.parsed.boolval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapHex(key string) (empty map[string]map[string]map[string]map[string][]byte) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string][]byte)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string][]byte)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[3].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string][]byte)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string][]byte)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string][]byte)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
entry := c.env[v14.key]
|
||||||
|
if (entry.dtype.baseType() == TypeHex.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14] = entry.parsed.binval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapMapInt(key string) (empty map[string]map[string]map[string]map[string]map[string]int64) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]map[string]int64)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[4].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]map[string]int64)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]map[string]int64)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]map[string]int64)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
retval[k11][k12][k13][k14] = make(map[string]int64)
|
||||||
|
for k15, v15 := range v14.next {
|
||||||
|
entry := c.env[v15.key]
|
||||||
|
if (entry.dtype.baseType() == TypeInt.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14][k15] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapMapMetric(key string) (empty map[string]map[string]map[string]map[string]map[string]int64) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]map[string]int64)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]map[string]int64)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[4].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]map[string]int64)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]map[string]int64)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]map[string]int64)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
retval[k11][k12][k13][k14] = make(map[string]int64)
|
||||||
|
for k15, v15 := range v14.next {
|
||||||
|
entry := c.env[v15.key]
|
||||||
|
if (entry.dtype.baseType() == TypeMetric.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14][k15] = entry.parsed.intval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapMapDuration(key string) (empty map[string]map[string]map[string]map[string]map[string]time.Duration) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]map[string]time.Duration)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]map[string]time.Duration)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[4].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]map[string]time.Duration)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]map[string]time.Duration)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]map[string]time.Duration)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
retval[k11][k12][k13][k14] = make(map[string]time.Duration)
|
||||||
|
for k15, v15 := range v14.next {
|
||||||
|
entry := c.env[v15.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDuration.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14][k15] = entry.parsed.durval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapMapString(key string) (empty map[string]map[string]map[string]map[string]map[string]string) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]map[string]string)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[4].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]map[string]string)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]map[string]string)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]map[string]string)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
retval[k11][k12][k13][k14] = make(map[string]string)
|
||||||
|
for k15, v15 := range v14.next {
|
||||||
|
entry := c.env[v15.key]
|
||||||
|
if (entry.dtype.baseType() == TypeString.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14][k15] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapMapDirectory(key string) (empty map[string]map[string]map[string]map[string]map[string]string) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]map[string]string)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]map[string]string)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[4].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]map[string]string)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]map[string]string)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]map[string]string)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
retval[k11][k12][k13][k14] = make(map[string]string)
|
||||||
|
for k15, v15 := range v14.next {
|
||||||
|
entry := c.env[v15.key]
|
||||||
|
if (entry.dtype.baseType() == TypeDirectory.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14][k15] = entry.parsed.strval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapMapBool(key string) (empty map[string]map[string]map[string]map[string]map[string]bool) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]map[string]bool)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]map[string]bool)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[4].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]map[string]bool)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]map[string]bool)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]map[string]bool)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
retval[k11][k12][k13][k14] = make(map[string]bool)
|
||||||
|
for k15, v15 := range v14.next {
|
||||||
|
entry := c.env[v15.key]
|
||||||
|
if (entry.dtype.baseType() == TypeBool.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14][k15] = entry.parsed.boolval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func (c *Config) GetMapMapMapMapMapHex(key string) (empty map[string]map[string]map[string]map[string]map[string][]byte) {
|
||||||
|
empty = make(map[string]map[string]map[string]map[string]map[string][]byte)
|
||||||
|
retval := make(map[string]map[string]map[string]map[string]map[string][]byte)
|
||||||
|
if c.parsed {
|
||||||
|
key = cleanKey(key)
|
||||||
|
v10, ok := c.mapEnv[4].next[key]
|
||||||
|
if ok {
|
||||||
|
for k11, v11 := range v10.next {
|
||||||
|
retval[k11] = make(map[string]map[string]map[string]map[string][]byte)
|
||||||
|
for k12, v12 := range v11.next {
|
||||||
|
retval[k11][k12] = make(map[string]map[string]map[string][]byte)
|
||||||
|
for k13, v13 := range v12.next {
|
||||||
|
retval[k11][k12][k13] = make(map[string]map[string][]byte)
|
||||||
|
for k14, v14 := range v13.next {
|
||||||
|
retval[k11][k12][k13][k14] = make(map[string][]byte)
|
||||||
|
for k15, v15 := range v14.next {
|
||||||
|
entry := c.env[v15.key]
|
||||||
|
if (entry.dtype.baseType() == TypeHex.baseType()) && (entry.parsed.err == nil) {
|
||||||
|
retval[k11][k12][k13][k14][k15] = entry.parsed.binval
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return retval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
51
datatype.go
51
datatype.go
@ -1,40 +1,69 @@
|
|||||||
package envconf
|
package envconf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DataType int
|
type DataType uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeNone DataType = iota
|
sizeBitmask DataType = 0xffff
|
||||||
TypeInt DataType = iota
|
typeBitmask DataType = sizeBitmask << 16
|
||||||
TypeMetric DataType = iota
|
|
||||||
TypeDuration DataType = iota
|
|
||||||
TypeString DataType = iota
|
|
||||||
TypeDirectory DataType = iota
|
|
||||||
TypeBool DataType = iota
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TypeNone DataType = iota << 16
|
||||||
|
TypeInt DataType = iota << 16
|
||||||
|
TypeMetric DataType = iota << 16
|
||||||
|
TypeDuration DataType = iota << 16
|
||||||
|
TypeString DataType = iota << 16
|
||||||
|
TypeDirectory DataType = iota << 16
|
||||||
|
TypeBool DataType = iota << 16
|
||||||
|
TypeHex DataType = iota << 16
|
||||||
|
)
|
||||||
|
|
||||||
|
func FixedHex(size uint16) DataType {
|
||||||
|
return TypeHex | DataType(size)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dtype DataType) baseType() DataType {
|
||||||
|
return dtype & typeBitmask
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dtype DataType) typeAndSize() (DataType, int) {
|
||||||
|
return (dtype & typeBitmask), int(dtype & sizeBitmask)
|
||||||
|
}
|
||||||
|
|
||||||
type cValue struct {
|
type cValue struct {
|
||||||
dtype DataType
|
dtype DataType
|
||||||
intval int64
|
intval int64
|
||||||
durval time.Duration
|
durval time.Duration
|
||||||
boolval bool
|
boolval bool
|
||||||
|
binval []byte
|
||||||
strval string
|
strval string
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dtype DataType) parse(key string, str string) (ret cValue) {
|
func (dtype DataType) parse(key string, str string) (ret cValue) {
|
||||||
info, ok := tInfo[dtype]
|
rdtype, size := dtype.typeAndSize()
|
||||||
|
info, ok := tInfo[rdtype]
|
||||||
if ok {
|
if ok {
|
||||||
return info.parser(key, str)
|
ret = info.parser(key, str, size)
|
||||||
|
if len(ret.binval) == 0 {
|
||||||
|
ret.binval = make([]byte, 0, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dtype DataType) String() string {
|
func (dtype DataType) String() string {
|
||||||
info, ok := tInfo[dtype]
|
rdtype, size := dtype.typeAndSize()
|
||||||
|
info, ok := tInfo[rdtype]
|
||||||
if ok {
|
if ok {
|
||||||
|
if size > 0 {
|
||||||
|
return fmt.Sprintf("%s%d", info.name, size)
|
||||||
|
}
|
||||||
return info.name
|
return info.name
|
||||||
}
|
}
|
||||||
return "invalid"
|
return "invalid"
|
||||||
|
174
envconf.go
174
envconf.go
@ -20,10 +20,48 @@ type cEntry struct {
|
|||||||
hasdef bool // Default value is defined
|
hasdef bool // Default value is defined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type keyLookupType struct {
|
||||||
|
key string
|
||||||
|
end bool
|
||||||
|
next map[string]*keyLookupType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kl *keyLookupType) setKey(parts []string, key string) {
|
||||||
|
if len(kl.next) == 0 {
|
||||||
|
kl.next = make(map[string]*keyLookupType)
|
||||||
|
}
|
||||||
|
if len(parts) > 0 {
|
||||||
|
firstPart := parts[0]
|
||||||
|
nextLookup, ok := kl.next[firstPart]
|
||||||
|
if ok {
|
||||||
|
nextLookup.setKey(parts[1:], key)
|
||||||
|
} else {
|
||||||
|
nextLookup := new(keyLookupType)
|
||||||
|
nextLookup.setKey(parts[1:], key)
|
||||||
|
kl.next[firstPart] = nextLookup
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
kl.key = key
|
||||||
|
kl.end = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kl *keyLookupType) print() {
|
||||||
|
if kl.end {
|
||||||
|
fmt.Println(kl.key)
|
||||||
|
fmt.Println("-----------------")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for key, val := range kl.next {
|
||||||
|
fmt.Println(key)
|
||||||
|
val.print()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
parsed bool
|
parsed bool
|
||||||
env map[string]cEntry
|
env map[string]cEntry
|
||||||
mapEnv map[string]map[string]cEntry
|
mapEnv *mapEnvType
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfig returns an envconf.Config that is used to read configuration from environment variables.
|
// NewConfig returns an envconf.Config that is used to read configuration from environment variables.
|
||||||
@ -33,27 +71,42 @@ func NewConfig() *Config {
|
|||||||
config := new(Config)
|
config := new(Config)
|
||||||
config.parsed = false
|
config.parsed = false
|
||||||
config.env = make(map[string]cEntry)
|
config.env = make(map[string]cEntry)
|
||||||
config.mapEnv = make(map[string]map[string]cEntry)
|
|
||||||
|
config.mapEnv = new(mapEnvType)
|
||||||
|
for level, _ := range config.mapEnv {
|
||||||
|
config.mapEnv[level] = new(keyLookupType)
|
||||||
|
}
|
||||||
|
|
||||||
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 := cleanKey(splitted[0])
|
key := cleanKey(splitted[0])
|
||||||
left, right, mappable := keySplit(key)
|
val := splitted[1]
|
||||||
|
|
||||||
|
splitted = strings.Split(key, "_")
|
||||||
|
maxParts := len(splitted)
|
||||||
|
splitted = append(splitted, make([]string, len(config.mapEnv), len(config.mapEnv))...)
|
||||||
if unicode.IsLetter(getFirstRune(key)) {
|
if unicode.IsLetter(getFirstRune(key)) {
|
||||||
var entry cEntry
|
var entry cEntry
|
||||||
entry.value = splitted[1]
|
entry.value = val
|
||||||
entry.dtype = TypeNone
|
entry.dtype = TypeNone
|
||||||
entry.unset = false
|
entry.unset = false
|
||||||
entry.empty = false
|
entry.empty = false
|
||||||
config.env[key] = entry
|
config.env[key] = entry
|
||||||
if mappable {
|
if len(splitted) > 1 {
|
||||||
if len(config.mapEnv[left]) == 0 {
|
for level := 0; level < len(config.mapEnv); level++ {
|
||||||
config.mapEnv[left] = make(map[string]cEntry)
|
for count := 0; count < maxParts-1-level; count++ {
|
||||||
}
|
parts := make([]string, level+2, level+2)
|
||||||
|
lastSplit := len(parts) - 1 + count
|
||||||
|
|
||||||
config.mapEnv[left][right] = entry
|
for partPos, _ := range parts {
|
||||||
|
parts[partPos] = splitted[partPos+count]
|
||||||
|
}
|
||||||
|
parts[0] = strings.Trim(strings.Join(splitted[:count+1], "_"), "_")
|
||||||
|
parts[len(parts)-1] = strings.Trim(strings.Join(splitted[lastSplit:], "_"), "_")
|
||||||
|
config.mapEnv[level].setKey(parts, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,11 +135,12 @@ func (c *Config) Define(key string, dtype DataType) {
|
|||||||
// Variables without a defined type will be ignored by Parse.
|
// Variables without a defined type will be ignored by Parse.
|
||||||
func (c *Config) DefineMap(key string, dtype DataType) {
|
func (c *Config) DefineMap(key string, dtype DataType) {
|
||||||
key = cleanKey(key)
|
key = cleanKey(key)
|
||||||
entries, ok := c.mapEnv[key]
|
entries, ok := c.mapEnv[0].next[key]
|
||||||
if ok {
|
if ok {
|
||||||
for mapKey, entry := range entries {
|
for _, entry := range entries.next {
|
||||||
entry.dtype = dtype
|
defEntry := c.env[entry.key]
|
||||||
c.mapEnv[key][mapKey] = entry
|
defEntry.dtype = dtype
|
||||||
|
c.env[entry.key] = defEntry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,13 +190,6 @@ func (c *Config) Parse() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range c.mapEnv {
|
|
||||||
for mk, mv := range v {
|
|
||||||
mv.parsed = mv.dtype.parse(k+"_"+mk, mv.value)
|
|
||||||
c.mapEnv[k][mk] = mv
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if failed {
|
if failed {
|
||||||
for k, v := range c.env {
|
for k, v := range c.env {
|
||||||
if (v.parsed.err == nil) && v.unset {
|
if (v.parsed.err == nil) && v.unset {
|
||||||
@ -234,17 +281,7 @@ func (c *Config) Status() (ok bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, v := range c.mapEnv {
|
|
||||||
for _, mv := range v {
|
|
||||||
err := mv.parsed.err
|
|
||||||
if err != nil {
|
|
||||||
ok = false
|
|
||||||
if !mv.empty {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !ok {
|
if !ok {
|
||||||
fmt.Fprintln(os.Stderr, "")
|
fmt.Fprintln(os.Stderr, "")
|
||||||
for _, v := range c.env {
|
for _, v := range c.env {
|
||||||
@ -283,52 +320,39 @@ func keySplit(key string) (left string, right string, ok bool) {
|
|||||||
|
|
||||||
func (c *Config) getRaw(key string, dtype DataType) (val cValue) {
|
func (c *Config) getRaw(key string, dtype DataType) (val cValue) {
|
||||||
val.dtype = TypeNone
|
val.dtype = TypeNone
|
||||||
|
val.binval = make([]byte, 0, 0)
|
||||||
if c.parsed {
|
if c.parsed {
|
||||||
key = cleanKey(key)
|
key = cleanKey(key)
|
||||||
entry, ok := c.env[key]
|
entry, ok := c.env[key]
|
||||||
if ok && (entry.dtype == dtype) {
|
if ok && (entry.dtype.baseType() == dtype.baseType()) {
|
||||||
return entry.parsed
|
return entry.parsed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) getRawMap(key string, dtype DataType) (empty map[string]cValue) {
|
// Returns the value of an environment variable.
|
||||||
empty = make(map[string]cValue)
|
|
||||||
retval := make(map[string]cValue)
|
|
||||||
if c.parsed {
|
|
||||||
key = cleanKey(key)
|
|
||||||
entries, ok := c.mapEnv[key]
|
|
||||||
|
|
||||||
if ok {
|
|
||||||
for k, v := range entries {
|
|
||||||
if v.dtype == dtype {
|
|
||||||
retval[k] = v.parsed
|
|
||||||
} else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return retval
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInt returns the value of an environment variable.
|
|
||||||
// If the variable is not defined as envconf.TypeInt the function will return 0.
|
// If the variable is not defined as envconf.TypeInt the function will return 0.
|
||||||
func (c *Config) GetInt(key string) int64 {
|
func (c *Config) GetInt(key string) int64 {
|
||||||
val := c.getRaw(key, TypeInt)
|
val := c.getRaw(key, TypeInt)
|
||||||
return val.intval
|
return val.intval
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMetric returns the value of an environment variable.
|
// Returns the value of an environment variable.
|
||||||
|
// If the variable is not defined as envconf.TypeHex the function will return []byte{}.
|
||||||
|
func (c *Config) GetHex(key string) []byte {
|
||||||
|
val := c.getRaw(key, TypeHex)
|
||||||
|
return val.binval
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the value of an environment variable.
|
||||||
// If the variable is not defined as envconf.TypeMetric the function will return 0.
|
// If the variable is not defined as envconf.TypeMetric the function will return 0.
|
||||||
func (c *Config) GetMetric(key string) int64 {
|
func (c *Config) GetMetric(key string) int64 {
|
||||||
val := c.getRaw(key, TypeMetric)
|
val := c.getRaw(key, TypeMetric)
|
||||||
return val.intval
|
return val.intval
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDirectory returns the value of an environment variable.
|
// Returns the value of an environment variable.
|
||||||
// If the variable is not defined as envconf.TypeDirectory the
|
// If the variable is not defined as envconf.TypeDirectory the
|
||||||
// function will return the empty string.
|
// function will return the empty string.
|
||||||
func (c *Config) GetDirectory(key string) string {
|
func (c *Config) GetDirectory(key string) string {
|
||||||
@ -336,7 +360,7 @@ func (c *Config) GetDirectory(key string) string {
|
|||||||
return val.strval
|
return val.strval
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetString returns the value of an environment variable.
|
// Returns the value of an environment variable.
|
||||||
// If the variable is not defined as envconf.TypeString the
|
// If the variable is not defined as envconf.TypeString the
|
||||||
// function will return the empty string.
|
// function will return the empty string.
|
||||||
func (c *Config) GetString(key string) string {
|
func (c *Config) GetString(key string) string {
|
||||||
@ -344,7 +368,7 @@ func (c *Config) GetString(key string) string {
|
|||||||
return val.strval
|
return val.strval
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDuration returns the value of an environment variable.
|
// Returns the value of an environment variable.
|
||||||
// If the variable is not defined as envconf.TypeDuration the
|
// If the variable is not defined as envconf.TypeDuration the
|
||||||
// function will return time.Duration(0).
|
// function will return time.Duration(0).
|
||||||
func (c *Config) GetDuration(key string) time.Duration {
|
func (c *Config) GetDuration(key string) time.Duration {
|
||||||
@ -352,7 +376,7 @@ func (c *Config) GetDuration(key string) time.Duration {
|
|||||||
return val.durval
|
return val.durval
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBool returns the value of an environment variable.
|
// Returns the value of an environment variable.
|
||||||
// If the variable is not defined as envconf.TypeBool the
|
// If the variable is not defined as envconf.TypeBool the
|
||||||
// function will return false.
|
// function will return false.
|
||||||
func (c *Config) GetBool(key string) bool {
|
func (c *Config) GetBool(key string) bool {
|
||||||
@ -360,38 +384,6 @@ func (c *Config) GetBool(key string) bool {
|
|||||||
return val.boolval
|
return val.boolval
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) GetMapInt(key string) (retval map[string]int64) {
|
|
||||||
retval = make(map[string]int64)
|
|
||||||
for k, v := range c.getRawMap(key, TypeInt) {
|
|
||||||
retval[k] = v.intval
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) GetMapDuration(key string) (retval map[string]time.Duration) {
|
|
||||||
retval = make(map[string]time.Duration)
|
|
||||||
for k, v := range c.getRawMap(key, TypeDuration) {
|
|
||||||
retval[k] = v.durval
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) GetMapString(key string) (retval map[string]string) {
|
|
||||||
retval = make(map[string]string)
|
|
||||||
for k, v := range c.getRawMap(key, TypeString) {
|
|
||||||
retval[k] = v.strval
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Config) GetMapBool(key string) (retval map[string]bool) {
|
|
||||||
retval = make(map[string]bool)
|
|
||||||
for k, v := range c.getRawMap(key, TypeBool) {
|
|
||||||
retval[k] = v.boolval
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFirstRune(str string) rune {
|
func getFirstRune(str string) rune {
|
||||||
for _, v := range str {
|
for _, v := range str {
|
||||||
return v
|
return v
|
||||||
|
155
generate.py
Executable file
155
generate.py
Executable file
@ -0,0 +1,155 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import typing
|
||||||
|
import tempfile
|
||||||
|
import os.path
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class DataType:
|
||||||
|
const_type: str
|
||||||
|
go_type: str
|
||||||
|
sig_type: str
|
||||||
|
value_type: str
|
||||||
|
|
||||||
|
|
||||||
|
def get_return_type(levels: int, dtype: str) -> str:
|
||||||
|
return ("map[string]" * levels) + dtype
|
||||||
|
|
||||||
|
|
||||||
|
def get_signature(levels: int, data_type: DataType) -> str:
|
||||||
|
return (
|
||||||
|
"func (c *Config) Get"
|
||||||
|
+ ("Map" * levels)
|
||||||
|
+ data_type.sig_type
|
||||||
|
+ "(key string) (empty "
|
||||||
|
+ get_return_type(levels, data_type.go_type)
|
||||||
|
+ ") {"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_empty_def(levels: int, data_type: DataType) -> str:
|
||||||
|
return "empty = make(" + get_return_type(levels, data_type.go_type) + ")"
|
||||||
|
|
||||||
|
|
||||||
|
def get_nested_keys(levels: int) -> str:
|
||||||
|
txt = ""
|
||||||
|
for count in range(levels):
|
||||||
|
txt += "[k" + str(count + 11) + "]"
|
||||||
|
return txt
|
||||||
|
|
||||||
|
|
||||||
|
def get_retval_def(levels: int, current_level: int, data_type: DataType) -> str:
|
||||||
|
base = "retval := make("
|
||||||
|
if current_level > 0:
|
||||||
|
base = "retval" + get_nested_keys(current_level) + " = make("
|
||||||
|
return base + get_return_type(levels - current_level, data_type.go_type) + ")"
|
||||||
|
|
||||||
|
|
||||||
|
def get_entries(levels: int) -> str:
|
||||||
|
return f"v10, ok := c.mapEnv[{levels-1}].next[key]"
|
||||||
|
|
||||||
|
|
||||||
|
def get_entry(levels: int) -> str:
|
||||||
|
return f"entry := c.env[v{levels + 11}.key]"
|
||||||
|
|
||||||
|
|
||||||
|
def set_value(levels: int, data_type: DataType) -> str:
|
||||||
|
return f"retval{get_nested_keys(levels + 1)} = entry.parsed.{data_type.value_type}"
|
||||||
|
|
||||||
|
|
||||||
|
def get_loop(levels: int) -> str:
|
||||||
|
return f"for k{levels + 11}, v{levels + 11} := range v{levels + 10}.next {{"
|
||||||
|
|
||||||
|
|
||||||
|
def get_function(file: typing.TextIO, levels: int, data_type: DataType):
|
||||||
|
print(get_signature(levels, data_type), file=file)
|
||||||
|
print(get_empty_def(levels, data_type), file=file)
|
||||||
|
print(get_retval_def(levels, 0, data_type), file=file)
|
||||||
|
print("if c.parsed {", file=file)
|
||||||
|
print("key = cleanKey(key)", file=file)
|
||||||
|
print(get_entries(levels), file=file)
|
||||||
|
print("if ok {", file=file)
|
||||||
|
for level in range(levels - 1):
|
||||||
|
print(get_loop(level), file=file)
|
||||||
|
print(get_retval_def(levels, level + 1, data_type), file=file)
|
||||||
|
print(get_loop(levels - 1), file=file)
|
||||||
|
print(get_entry(levels - 1), file=file)
|
||||||
|
print(
|
||||||
|
f"if (entry.dtype.baseType() == {data_type.const_type}.baseType()) && (entry.parsed.err == nil) {{",
|
||||||
|
file=file,
|
||||||
|
)
|
||||||
|
print(set_value(levels - 1, data_type), file=file)
|
||||||
|
print("} else {", file=file)
|
||||||
|
print("return", file=file)
|
||||||
|
print("};" * (levels + 1), file=file)
|
||||||
|
print("return retval", file=file)
|
||||||
|
print("}", file=file)
|
||||||
|
print("}", file=file)
|
||||||
|
print("return", file=file)
|
||||||
|
print("}", file=file)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
data_types = [
|
||||||
|
DataType(
|
||||||
|
const_type="TypeInt", go_type="int64", sig_type="Int", value_type="intval"
|
||||||
|
),
|
||||||
|
DataType(
|
||||||
|
const_type="TypeMetric",
|
||||||
|
go_type="int64",
|
||||||
|
sig_type="Metric",
|
||||||
|
value_type="intval",
|
||||||
|
),
|
||||||
|
DataType(
|
||||||
|
const_type="TypeDuration",
|
||||||
|
go_type="time.Duration",
|
||||||
|
sig_type="Duration",
|
||||||
|
value_type="durval",
|
||||||
|
),
|
||||||
|
DataType(
|
||||||
|
const_type="TypeString",
|
||||||
|
go_type="string",
|
||||||
|
sig_type="String",
|
||||||
|
value_type="strval",
|
||||||
|
),
|
||||||
|
DataType(
|
||||||
|
const_type="TypeDirectory",
|
||||||
|
go_type="string",
|
||||||
|
sig_type="Directory",
|
||||||
|
value_type="strval",
|
||||||
|
),
|
||||||
|
DataType(
|
||||||
|
const_type="TypeBool", go_type="bool", sig_type="Bool", value_type="boolval"
|
||||||
|
),
|
||||||
|
DataType(
|
||||||
|
const_type="TypeHex", go_type="[]byte", sig_type="Hex", value_type="binval"
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
levels = 5
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory() as pathname:
|
||||||
|
code_file = os.path.join(pathname, "code.go")
|
||||||
|
with open(code_file, mode="w", encoding="utf-8") as f:
|
||||||
|
print("package envconf", file=f)
|
||||||
|
print('import "time"', file=f)
|
||||||
|
print(f"type mapEnvType [{levels}]*keyLookupType", file=f)
|
||||||
|
for level in range(levels):
|
||||||
|
for data_type in data_types:
|
||||||
|
get_function(f, level + 1, data_type)
|
||||||
|
if subprocess.run(["go", "fmt", code_file], check=True).returncode == 0:
|
||||||
|
shutil.copyfile(
|
||||||
|
code_file,
|
||||||
|
os.path.join(
|
||||||
|
os.path.dirname(os.path.realpath(__file__)), "auto_generated.go"
|
||||||
|
),
|
||||||
|
follow_symlinks=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
27
parsers.go
27
parsers.go
@ -1,6 +1,7 @@
|
|||||||
package envconf
|
package envconf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -10,7 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseInt(key string, str string) (ret cValue) {
|
func parseInt(key string, str string, _ int) (ret cValue) {
|
||||||
val, err := strconv.ParseInt(str, 10, 64)
|
val, err := strconv.ParseInt(str, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ret.intval = val
|
ret.intval = val
|
||||||
@ -20,7 +21,7 @@ func parseInt(key string, str string) (ret cValue) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMetric(key string, str string) (ret cValue) {
|
func parseMetric(key string, str string, _ int) (ret cValue) {
|
||||||
mod := int64(1)
|
mod := int64(1)
|
||||||
str = strings.ToUpper(str)
|
str = strings.ToUpper(str)
|
||||||
if strings.HasSuffix(str, "K") {
|
if strings.HasSuffix(str, "K") {
|
||||||
@ -45,7 +46,7 @@ func parseMetric(key string, str string) (ret cValue) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDuration(key string, str string) (ret cValue) {
|
func parseDuration(key string, str string, _ int) (ret cValue) {
|
||||||
val, err := time.ParseDuration(str)
|
val, err := time.ParseDuration(str)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ret.durval = val
|
ret.durval = val
|
||||||
@ -55,7 +56,7 @@ func parseDuration(key string, str string) (ret cValue) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseBool(key string, str string) (ret cValue) {
|
func parseBool(key string, str string, _ int) (ret cValue) {
|
||||||
val, err := strconv.ParseBool(str)
|
val, err := strconv.ParseBool(str)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ret.boolval = val
|
ret.boolval = val
|
||||||
@ -65,7 +66,21 @@ func parseBool(key string, str string) (ret cValue) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDirectory(_ string, str string) (ret cValue) {
|
func parseHex(key string, str string, size int) (ret cValue) {
|
||||||
|
val, err := hex.DecodeString(str)
|
||||||
|
if err == nil && (size == 0 || size == len(val)) {
|
||||||
|
ret.binval = val
|
||||||
|
} else {
|
||||||
|
if size == 0 {
|
||||||
|
ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type hex.`, key))
|
||||||
|
} else {
|
||||||
|
ret.err = errors.New(fmt.Sprintf(`Environment variable "%s" is not of type hex%d.`, key, size))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseDirectory(_ string, str string, _ int) (ret cValue) {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if path.IsAbs(str) {
|
if path.IsAbs(str) {
|
||||||
@ -79,7 +94,7 @@ func parseDirectory(_ string, str string) (ret cValue) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseString(_ string, str string) (ret cValue) {
|
func parseString(_ string, str string, _ int) (ret cValue) {
|
||||||
ret.strval = str
|
ret.strval = str
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
31
tests/build.sh
Executable file
31
tests/build.sh
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
dir=$(dirname $(realpath $0))
|
||||||
|
export GO111MODULE=on
|
||||||
|
export GOPROXY=direct
|
||||||
|
export GOPATH=${dir}/buildenv/deps
|
||||||
|
|
||||||
|
mkdir -p ${dir}/buildenv
|
||||||
|
chmod -R 755 ${dir}/buildenv
|
||||||
|
rm -rf ${dir}/buildenv
|
||||||
|
|
||||||
|
mkdir -p "${dir}/buildenv/src"
|
||||||
|
mkdir -p ${GOPATH}/src
|
||||||
|
mkdir -p ${dir}/bin
|
||||||
|
|
||||||
|
cp -r "${dir}/main.go" "${dir}/buildenv/src/main.go"
|
||||||
|
cd ${dir}/buildenv
|
||||||
|
|
||||||
|
go mod init src
|
||||||
|
go mod tidy
|
||||||
|
|
||||||
|
package_name=$(ls ${dir}/buildenv/deps/pkg/mod/git.purser.it/roypur | tr -d "\n")
|
||||||
|
package_dir="${dir}/buildenv/deps/pkg/mod/git.purser.it/roypur/${package_name}"
|
||||||
|
|
||||||
|
chmod -R 777 "${dir}/buildenv/deps"
|
||||||
|
rm -R "${package_dir}"
|
||||||
|
mkdir -p "${package_dir}"
|
||||||
|
|
||||||
|
cp $(dirname ${dir})/*.go ${package_dir}
|
||||||
|
|
||||||
|
cd "${dir}"
|
||||||
|
go build -o "${dir}/bin/test"
|
16
tests/main.go
Normal file
16
tests/main.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"git.purser.it/roypur/envconf"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
conf := envconf.NewConfig()
|
||||||
|
conf.Define("this_is_a_map", envconf.TypeInt)
|
||||||
|
conf.DefineMap("test_map", envconf.TypeInt)
|
||||||
|
conf.Parse()
|
||||||
|
conf.Status()
|
||||||
|
fmt.Println(conf.GetMapMapMapMapMapInt("test_map"))
|
||||||
|
fmt.Println(conf.GetInt("this_is_a_map"))
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package envconf
|
package envconf
|
||||||
|
|
||||||
type dataTypeInfo struct {
|
type dataTypeInfo struct {
|
||||||
parser func(string, string) cValue
|
parser func(string, string, int) cValue
|
||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14,6 +14,8 @@ func init() {
|
|||||||
var durInfo dataTypeInfo
|
var durInfo dataTypeInfo
|
||||||
var strInfo dataTypeInfo
|
var strInfo dataTypeInfo
|
||||||
var dirInfo dataTypeInfo
|
var dirInfo dataTypeInfo
|
||||||
|
var hexInfo dataTypeInfo
|
||||||
|
|
||||||
var boolInfo dataTypeInfo
|
var boolInfo dataTypeInfo
|
||||||
|
|
||||||
intInfo.name = "int"
|
intInfo.name = "int"
|
||||||
@ -21,6 +23,7 @@ func init() {
|
|||||||
durInfo.name = "duration"
|
durInfo.name = "duration"
|
||||||
dirInfo.name = "directory"
|
dirInfo.name = "directory"
|
||||||
strInfo.name = "string"
|
strInfo.name = "string"
|
||||||
|
hexInfo.name = "hex"
|
||||||
boolInfo.name = "bool"
|
boolInfo.name = "bool"
|
||||||
|
|
||||||
intInfo.parser = parseInt
|
intInfo.parser = parseInt
|
||||||
@ -28,6 +31,8 @@ func init() {
|
|||||||
durInfo.parser = parseDuration
|
durInfo.parser = parseDuration
|
||||||
dirInfo.parser = parseDirectory
|
dirInfo.parser = parseDirectory
|
||||||
strInfo.parser = parseString
|
strInfo.parser = parseString
|
||||||
|
|
||||||
|
hexInfo.parser = parseHex
|
||||||
boolInfo.parser = parseBool
|
boolInfo.parser = parseBool
|
||||||
|
|
||||||
tInfo[TypeInt] = intInfo
|
tInfo[TypeInt] = intInfo
|
||||||
@ -35,5 +40,6 @@ func init() {
|
|||||||
tInfo[TypeDuration] = durInfo
|
tInfo[TypeDuration] = durInfo
|
||||||
tInfo[TypeString] = strInfo
|
tInfo[TypeString] = strInfo
|
||||||
tInfo[TypeDirectory] = dirInfo
|
tInfo[TypeDirectory] = dirInfo
|
||||||
|
tInfo[TypeHex] = hexInfo
|
||||||
tInfo[TypeBool] = boolInfo
|
tInfo[TypeBool] = boolInfo
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user