auto generated nested mapping

This commit is contained in:
Roy Olav Purser 2022-09-23 20:22:24 +02:00
parent eef48c1d0a
commit b901036467
Signed by: roypur
GPG Key ID: 90142918D5E59AD3
6 changed files with 1047 additions and 593 deletions

916
auto_generated.go Normal file
View 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
}

View File

@ -31,9 +31,15 @@ func (kl *keyLookupType) setKey(parts []string, key string) {
kl.next = make(map[string]*keyLookupType) kl.next = make(map[string]*keyLookupType)
} }
if len(parts) > 0 { if len(parts) > 0 {
firstPart := parts[0]
nextLookup, ok := kl.next[firstPart]
if ok {
nextLookup.setKey(parts[1:], key)
} else {
nextLookup := new(keyLookupType) nextLookup := new(keyLookupType)
nextLookup.setKey(parts[1:], key) nextLookup.setKey(parts[1:], key)
kl.next[parts[0]] = nextLookup kl.next[firstPart] = nextLookup
}
} else { } else {
kl.key = key kl.key = key
kl.end = true kl.end = true
@ -52,12 +58,10 @@ func (kl *keyLookupType) print() {
} }
} }
type mapEnvType [5]*keyLookupType
type Config struct { type Config struct {
parsed bool parsed bool
env map[string]cEntry env map[string]cEntry
mapEnv mapEnvType 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.
@ -67,6 +71,8 @@ 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 = new(mapEnvType)
for level, _ := range config.mapEnv { for level, _ := range config.mapEnv {
config.mapEnv[level] = new(keyLookupType) config.mapEnv[level] = new(keyLookupType)
} }
@ -76,7 +82,10 @@ func NewConfig() *Config {
if len(splitted) == 2 { if len(splitted) == 2 {
key := cleanKey(splitted[0]) key := cleanKey(splitted[0])
val := splitted[1] val := splitted[1]
splitted = append(strings.Split(key, "_"), make([]string, len(config.mapEnv), len(config.mapEnv))...)
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 = val entry.value = val
@ -85,25 +94,18 @@ func NewConfig() *Config {
entry.empty = false entry.empty = false
config.env[key] = entry config.env[key] = entry
if len(splitted) > 1 { if len(splitted) > 1 {
for level := 1; level <= len(config.mapEnv); level++ { for level := 0; level < len(config.mapEnv); level++ {
for count := 0; count < level; count++ { for count := 0; count < maxParts-1-level; count++ {
parts := make([]string, level, level) parts := make([]string, level+2, level+2)
parts[0] = strings.Trim(strings.Join(splitted[:count+1], "_"), "_") lastSplit := len(parts) - 1 + count
for partPos, _ := range parts { for partPos, _ := range parts {
if partPos > 0 {
if partPos+1 == len(parts) {
parts[partPos] = strings.Trim(strings.Join(splitted[partPos+count:], "_"), "_")
} else {
parts[partPos] = splitted[partPos+count] parts[partPos] = splitted[partPos+count]
} }
} parts[0] = strings.Trim(strings.Join(splitted[:count+1], "_"), "_")
} parts[len(parts)-1] = strings.Trim(strings.Join(splitted[lastSplit:], "_"), "_")
if parts[len(parts)-1] == "" {
break
}
config.mapEnv[level].setKey(parts, key) config.mapEnv[level].setKey(parts, key)
} }
config.mapEnv[level].print()
} }
} }
} }
@ -329,146 +331,6 @@ func (c *Config) getRaw(key string, dtype DataType) (val cValue) {
return return
} }
func (c *Config) getRawMap(key string, dtype DataType) (empty map[string]cValue) {
empty = make(map[string]cValue)
retval := make(map[string]cValue)
if c.parsed {
key = cleanKey(key)
entries, ok := c.mapEnv[0].next[key]
if ok {
for k, v := range entries.next {
entry := c.env[v.key]
if (entry.dtype.baseType() == dtype.baseType()) && (entry.parsed.err == nil) {
retval[k] = entry.parsed
} else {
return
}
}
return retval
}
}
return
}
func (c *Config) getRawMapMap(key string, dtype DataType) (empty map[string]map[string]cValue) {
empty = make(map[string]map[string]cValue)
retval := make(map[string]map[string]cValue)
if c.parsed {
key = cleanKey(key)
entries, ok := c.mapMapEnv[key]
if ok {
for k1, v1 := range entries {
retval[k1] = make(map[string]cValue)
for k2, v2 := range v1 {
entry := c.env[v2]
if (entry.dtype.baseType() == dtype.baseType()) && (entry.parsed.err == nil) {
retval[k1][k2] = entry.parsed
} else {
return
}
}
}
return retval
}
}
return
}
func (c *Config) getRawMapMapMap(key string, dtype DataType) (empty map[string]map[string]map[string]cValue) {
empty = make(map[string]map[string]map[string]cValue)
retval := make(map[string]map[string]map[string]cValue)
if c.parsed {
key = cleanKey(key)
entries, ok := c.mapMapMapEnv[key]
if ok {
for k1, v1 := range entries {
retval[k1] = make(map[string]map[string]cValue)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]cValue)
for k3, v3 := range v2 {
entry := c.env[v3]
if (entry.dtype.baseType() == dtype.baseType()) && (entry.parsed.err == nil) {
retval[k1][k2][k3] = entry.parsed
} else {
return
}
}
}
}
return retval
}
}
return
}
func (c *Config) getRawMapMapMapMap(key string, dtype DataType) (empty map[string]map[string]map[string]map[string]cValue) {
empty = make(map[string]map[string]map[string]map[string]cValue)
retval := make(map[string]map[string]map[string]map[string]cValue)
if c.parsed {
key = cleanKey(key)
entries, ok := c.mapMapMapMapEnv[key]
if ok {
for k1, v1 := range entries {
retval[k1] = make(map[string]map[string]map[string]cValue)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]cValue)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]cValue)
for k4, v4 := range v3 {
entry := c.env[v4]
if (entry.dtype.baseType() == dtype.baseType()) && (entry.parsed.err == nil) {
retval[k1][k2][k3][k4] = entry.parsed
} else {
return
}
}
}
}
}
return retval
}
}
return
}
func (c *Config) getRawMapMapMapMapMap(key string, dtype DataType) (empty map[string]map[string]map[string]map[string]map[string]cValue) {
empty = make(map[string]map[string]map[string]map[string]map[string]cValue)
retval := make(map[string]map[string]map[string]map[string]map[string]cValue)
if c.parsed {
key = cleanKey(key)
entries, ok := c.mapMapMapMapMapEnv[key]
if ok {
for k1, v1 := range entries {
retval[k1] = make(map[string]map[string]map[string]map[string]cValue)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]map[string]cValue)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]map[string]cValue)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = make(map[string]cValue)
for k5, v5 := range v4 {
entry := c.env[v5]
if (entry.dtype.baseType() == dtype.baseType()) && (entry.parsed.err == nil) {
retval[k1][k2][k3][k4][k5] = entry.parsed
} else {
return
}
}
}
}
}
}
return retval
}
}
return
}
// Returns the value of an environment variable. // 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 {
@ -522,356 +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 (c *Config) GetMapHex(key string) (retval map[string][]byte) {
retval = make(map[string][]byte)
for k, v := range c.getRawMap(key, TypeHex) {
retval[k] = v.binval
}
return
}
func (c *Config) GetMapMapInt(key string) (retval map[string]map[string]int64) {
retval = make(map[string]map[string]int64)
for k1, v1 := range c.getRawMapMap(key, TypeInt) {
retval[k1] = make(map[string]int64)
for k2, v2 := range v1 {
retval[k1][k2] = v2.intval
}
}
return
}
func (c *Config) GetMapMapDuration(key string) (retval map[string]map[string]time.Duration) {
retval = make(map[string]map[string]time.Duration)
for k1, v1 := range c.getRawMapMap(key, TypeDuration) {
retval[k1] = make(map[string]time.Duration)
for k2, v2 := range v1 {
retval[k1][k2] = v2.durval
}
}
return
}
func (c *Config) GetMapMapString(key string) (retval map[string]map[string]string) {
retval = make(map[string]map[string]string)
for k1, v1 := range c.getRawMapMap(key, TypeString) {
retval[k1] = make(map[string]string)
for k2, v2 := range v1 {
retval[k1][k2] = v2.strval
}
}
return
}
func (c *Config) GetMapMapBool(key string) (retval map[string]map[string]bool) {
retval = make(map[string]map[string]bool)
for k1, v1 := range c.getRawMapMap(key, TypeBool) {
retval[k1] = make(map[string]bool)
for k2, v2 := range v1 {
retval[k1][k2] = v2.boolval
}
}
return
}
func (c *Config) GetMapMapHex(key string) (retval map[string]map[string][]byte) {
retval = make(map[string]map[string][]byte)
for k1, v1 := range c.getRawMapMap(key, TypeHex) {
retval[k1] = make(map[string][]byte)
for k2, v2 := range v1 {
retval[k1][k2] = v2.binval
}
}
return
}
func (c *Config) GetMapMapMapInt(key string) (retval map[string]map[string]map[string]int64) {
retval = make(map[string]map[string]map[string]int64)
for k1, v1 := range c.getRawMapMapMap(key, TypeInt) {
retval[k1] = make(map[string]map[string]int64)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]int64)
for k3, v3 := range v2 {
retval[k1][k2][k3] = v3.intval
}
}
}
return
}
func (c *Config) GetMapMapMapDuration(key string) (retval map[string]map[string]map[string]time.Duration) {
retval = make(map[string]map[string]map[string]time.Duration)
for k1, v1 := range c.getRawMapMapMap(key, TypeDuration) {
retval[k1] = make(map[string]map[string]time.Duration)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]time.Duration)
for k3, v3 := range v2 {
retval[k1][k2][k3] = v3.durval
}
}
}
return
}
func (c *Config) GetMapMapMapString(key string) (retval map[string]map[string]map[string]string) {
retval = make(map[string]map[string]map[string]string)
for k1, v1 := range c.getRawMapMapMap(key, TypeString) {
retval[k1] = make(map[string]map[string]string)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]string)
for k3, v3 := range v2 {
retval[k1][k2][k3] = v3.strval
}
}
}
return
}
func (c *Config) GetMapMapMapBool(key string) (retval map[string]map[string]map[string]bool) {
retval = make(map[string]map[string]map[string]bool)
for k1, v1 := range c.getRawMapMapMap(key, TypeBool) {
retval[k1] = make(map[string]map[string]bool)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]bool)
for k3, v3 := range v2 {
retval[k1][k2][k3] = v3.boolval
}
}
}
return
}
func (c *Config) GetMapMapMapHex(key string) (retval map[string]map[string]map[string][]byte) {
retval = make(map[string]map[string]map[string][]byte)
for k1, v1 := range c.getRawMapMapMap(key, TypeHex) {
retval[k1] = make(map[string]map[string][]byte)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string][]byte)
for k3, v3 := range v2 {
retval[k1][k2][k3] = v3.binval
}
}
}
return
}
func (c *Config) GetMapMapMapMapInt(key string) (retval map[string]map[string]map[string]map[string]int64) {
retval = make(map[string]map[string]map[string]map[string]int64)
for k1, v1 := range c.getRawMapMapMapMap(key, TypeInt) {
retval[k1] = make(map[string]map[string]map[string]int64)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]int64)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]int64)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = v4.intval
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapDuration(key string) (retval map[string]map[string]map[string]map[string]time.Duration) {
retval = make(map[string]map[string]map[string]map[string]time.Duration)
for k1, v1 := range c.getRawMapMapMapMap(key, TypeDuration) {
retval[k1] = make(map[string]map[string]map[string]time.Duration)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]time.Duration)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]time.Duration)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = v4.durval
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapString(key string) (retval map[string]map[string]map[string]map[string]string) {
retval = make(map[string]map[string]map[string]map[string]string)
for k1, v1 := range c.getRawMapMapMapMap(key, TypeString) {
retval[k1] = make(map[string]map[string]map[string]string)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]string)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]string)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = v4.strval
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapBool(key string) (retval map[string]map[string]map[string]map[string]bool) {
retval = make(map[string]map[string]map[string]map[string]bool)
for k1, v1 := range c.getRawMapMapMapMap(key, TypeBool) {
retval[k1] = make(map[string]map[string]map[string]bool)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]bool)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]bool)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = v4.boolval
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapHex(key string) (retval map[string]map[string]map[string]map[string][]byte) {
retval = make(map[string]map[string]map[string]map[string][]byte)
for k1, v1 := range c.getRawMapMapMapMap(key, TypeHex) {
retval[k1] = make(map[string]map[string]map[string][]byte)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string][]byte)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string][]byte)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = v4.binval
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapMapInt(key string) (retval map[string]map[string]map[string]map[string]map[string]int64) {
retval = make(map[string]map[string]map[string]map[string]map[string]int64)
for k1, v1 := range c.getRawMapMapMapMapMap(key, TypeInt) {
retval[k1] = make(map[string]map[string]map[string]map[string]int64)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]map[string]int64)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]map[string]int64)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = make(map[string]int64)
for k5, v5 := range v4 {
retval[k1][k2][k3][k4][k5] = v5.intval
}
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapMapDuration(key string) (retval 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)
for k1, v1 := range c.getRawMapMapMapMapMap(key, TypeDuration) {
retval[k1] = make(map[string]map[string]map[string]map[string]time.Duration)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]map[string]time.Duration)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]map[string]time.Duration)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = make(map[string]time.Duration)
for k5, v5 := range v4 {
retval[k1][k2][k3][k4][k5] = v5.durval
}
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapMapString(key string) (retval map[string]map[string]map[string]map[string]map[string]string) {
retval = make(map[string]map[string]map[string]map[string]map[string]string)
for k1, v1 := range c.getRawMapMapMapMapMap(key, TypeString) {
retval[k1] = make(map[string]map[string]map[string]map[string]string)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]map[string]string)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]map[string]string)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = make(map[string]string)
for k5, v5 := range v4 {
retval[k1][k2][k3][k4][k5] = v5.strval
}
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapMapBool(key string) (retval map[string]map[string]map[string]map[string]map[string]bool) {
retval = make(map[string]map[string]map[string]map[string]map[string]bool)
for k1, v1 := range c.getRawMapMapMapMapMap(key, TypeBool) {
retval[k1] = make(map[string]map[string]map[string]map[string]bool)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]map[string]bool)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]map[string]bool)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = make(map[string]bool)
for k5, v5 := range v4 {
retval[k1][k2][k3][k4][k5] = v5.boolval
}
}
}
}
}
return
}
func (c *Config) GetMapMapMapMapMapHex(key string) (retval map[string]map[string]map[string]map[string]map[string][]byte) {
retval = make(map[string]map[string]map[string]map[string]map[string][]byte)
for k1, v1 := range c.getRawMapMapMapMapMap(key, TypeHex) {
retval[k1] = make(map[string]map[string]map[string]map[string][]byte)
for k2, v2 := range v1 {
retval[k1][k2] = make(map[string]map[string]map[string][]byte)
for k3, v3 := range v2 {
retval[k1][k2][k3] = make(map[string]map[string][]byte)
for k4, v4 := range v3 {
retval[k1][k2][k3][k4] = make(map[string][]byte)
for k5, v5 := range v4 {
retval[k1][k2][k3][k4][k5] = v5.binval
}
}
}
}
}
return
}
func getFirstRune(str string) rune { func getFirstRune(str string) rune {
for _, v := range str { for _, v := range str {
return v return v

149
generate.py Normal file → Executable file
View File

@ -1,73 +1,91 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import typing 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: def get_return_type(levels: int, dtype: str) -> str:
return ("map[string]" * levels) + dtype return ("map[string]" * levels) + dtype
def get_signature(levels: int, sig_dtype: str, dtype: str) -> str: def get_signature(levels: int, data_type: DataType) -> str:
return ( return (
"func (c *Config) get" "func (c *Config) Get"
+ ("Map" * levels) + ("Map" * levels)
+ sig_dtype + data_type.sig_type
+ "(key string) (empty " + "(key string) (empty "
+ get_return_type(levels, dtype) + get_return_type(levels, data_type.go_type)
+ ") {" + ") {"
) )
def get_empty_def(levels: int, dtype: str) -> str: def get_empty_def(levels: int, data_type: DataType) -> str:
return "empty = make(" + get_return_type(levels, dtype) + ")" return "empty = make(" + get_return_type(levels, data_type.go_type) + ")"
def get_nested_keys(levels: int) -> str: def get_nested_keys(levels: int) -> str:
txt = "" txt = ""
for count in range(levels): for count in range(levels):
txt += "[k" + str(count + 10) + "]" txt += "[k" + str(count + 11) + "]"
return txt return txt
def get_retval_def(levels: int, current_level: int, dtype: str) -> str: def get_retval_def(levels: int, current_level: int, data_type: DataType) -> str:
base = "retval := make(" base = "retval := make("
if current_level > 0: if current_level > 0:
base = "retval" + get_nested_keys(current_level) + " = make(" base = "retval" + get_nested_keys(current_level) + " = make("
return base + get_return_type(levels - current_level, dtype) + ")" return base + get_return_type(levels - current_level, data_type.go_type) + ")"
def get_entries(levels: int) -> str: def get_entries(levels: int) -> str:
return f"v9, ok := c.mapEnv[{levels}].next[key]" return f"v10, ok := c.mapEnv[{levels-1}].next[key]"
def get_entry(levels: int) -> str: def get_entry(levels: int) -> str:
return f"entry := c.env[v{levels}.key]" 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: def get_loop(levels: int) -> str:
return f"for k{levels + 10}, v{levels + 10} := range v{levels + 9}.next {{" return f"for k{levels + 11}, v{levels + 11} := range v{levels + 10}.next {{"
def get_function(file: typing.TextIO, levels: int, sig_dtype: str, dtype: str): def get_function(file: typing.TextIO, levels: int, data_type: DataType):
print(get_signature(levels, sig_dtype, dtype), file=file) print(get_signature(levels, data_type), file=file)
print(get_empty_def(levels, dtype), file=file) print(get_empty_def(levels, data_type), file=file)
print(get_retval_def(levels, 0, dtype), file=file) print(get_retval_def(levels, 0, data_type), file=file)
print("if c.parsed {", file=file) print("if c.parsed {", file=file)
print("key = cleanKey(key)", file=file) print("key = cleanKey(key)", file=file)
print(get_entries(levels), file=file) print(get_entries(levels), file=file)
for level in range(levels): print("if ok {", file=file)
for level in range(levels - 1):
print(get_loop(level), file=file) print(get_loop(level), file=file)
print(get_retval_def(levels, level, dtype), file=file) print(get_retval_def(levels, level + 1, data_type), file=file)
print(get_loop(levels), file=file) print(get_loop(levels - 1), file=file)
print(get_entry(levels), file=file) print(get_entry(levels - 1), file=file)
print( print(
"if (entry.dtype.baseType() == dtype.baseType()) && (entry.parsed.err == nil) {", f"if (entry.dtype.baseType() == {data_type.const_type}.baseType()) && (entry.parsed.err == nil) {{",
file=file, file=file,
) )
print("retval[k] = entry.parsed", file=file) print(set_value(levels - 1, data_type), file=file)
print("} else {", file=file) print("} else {", file=file)
print("return", file=file) print("return", file=file)
print("}", file=file) print("};" * (levels + 1), file=file)
print("}", file=file)
print("return retval", file=file) print("return retval", file=file)
print("}", file=file) print("}", file=file)
print("}", file=file) print("}", file=file)
@ -75,32 +93,63 @@ def get_function(file: typing.TextIO, levels: int, sig_dtype: str, dtype: str):
print("}", file=file) print("}", file=file)
with open("generated_code.go", mode="w", encoding="utf-8") as f: 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("package envconf", file=f)
get_function(f, 3, "Int", "int64") 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__":
# func (c *Config) getRawMap(key string, dtype DataType) (empty map[string]cValue) { main()
# empty = make(map[string]cValue)
# retval := make(map[string]cValue)
# if c.parsed {
# key = cleanKey(key)
# entries, ok := c.mapEnv[0].next[key]
#
# if ok {
# for k, v := range entries.next {
# entry := c.env[v.key]
# if (entry.dtype.baseType() == dtype.baseType()) && (entry.parsed.err == nil) {
# retval[k] = entry.parsed
# } else {
# return
# }
# }
# return retval
# }
# }
# return
# }
#
#

View File

@ -1,25 +0,0 @@
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)
v9, ok := c.mapEnv[3].next[key]
for k10, v10 := range v9.next {
retval := make(map[string]map[string]map[string]int64)
for k11, v11 := range v10.next {
retval[k10] = make(map[string]map[string]int64)
for k12, v12 := range v11.next {
retval[k10][k11] = make(map[string]int64)
for k13, v13 := range v12.next {
entry := c.env[v3.key]
if (entry.dtype.baseType() == dtype.baseType()) && (entry.parsed.err == nil) {
retval[k] = entry.parsed
} else {
return
}
}
return retval
}
}
return
}

View File

@ -13,7 +13,6 @@ mkdir -p ${GOPATH}/src
mkdir -p ${dir}/bin mkdir -p ${dir}/bin
cp -r "${dir}/main.go" "${dir}/buildenv/src/main.go" cp -r "${dir}/main.go" "${dir}/buildenv/src/main.go"
cd ${dir}/buildenv cd ${dir}/buildenv
go mod init src go mod init src
@ -21,9 +20,12 @@ go mod tidy
package_name=$(ls ${dir}/buildenv/deps/pkg/mod/git.purser.it/roypur | tr -d "\n") 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}" package_dir="${dir}/buildenv/deps/pkg/mod/git.purser.it/roypur/${package_name}"
chmod -R 777 ${package_dir}
rm ${package_dir}/*.go chmod -R 777 "${dir}/buildenv/deps"
rm -R "${package_dir}"
mkdir -p "${package_dir}"
cp $(dirname ${dir})/*.go ${package_dir} cp $(dirname ${dir})/*.go ${package_dir}
go build -o "${dir}/bin/test" "src/main.go" cd "${dir}"
go build -o "${dir}/bin/test"

View File

@ -11,6 +11,6 @@ func main() {
conf.DefineMap("test_map", envconf.TypeInt) conf.DefineMap("test_map", envconf.TypeInt)
conf.Parse() conf.Parse()
conf.Status() conf.Status()
fmt.Println(conf.GetMapMapMapInt("test_map")) fmt.Println(conf.GetMapMapMapMapMapInt("test_map"))
fmt.Println(conf.GetInt("this_is_a_map")) fmt.Println(conf.GetInt("this_is_a_map"))
} }