normalize idp
This commit is contained in:
@@ -2,10 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
gofig "github.com/gookit/config/v2"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
@@ -107,38 +104,3 @@ func GetEnv() []string {
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// UnmapEnv loads values from the gooconf.Config argument and sets them in the expected destination.
|
||||
func (c *Config) UnmapEnv(gooconf *gofig.Config) error {
|
||||
vals := structMappings(c)
|
||||
for i := range vals {
|
||||
for j := range vals[i].EnvVars {
|
||||
// we need to guard against v != "" because this is the condition that checks that the value is set from the environment.
|
||||
// the `ok` guard is not enough, apparently.
|
||||
if v, ok := gooconf.GetValue(vals[i].EnvVars[j]); ok && v != "" {
|
||||
|
||||
// get the destination type from destination
|
||||
switch reflect.ValueOf(vals[i].Destination).Type().String() {
|
||||
case "*bool":
|
||||
r := gooconf.Bool(vals[i].EnvVars[j])
|
||||
*vals[i].Destination.(*bool) = r
|
||||
case "*string":
|
||||
r := gooconf.String(vals[i].EnvVars[j])
|
||||
*vals[i].Destination.(*string) = r
|
||||
case "*int":
|
||||
r := gooconf.Int(vals[i].EnvVars[j])
|
||||
*vals[i].Destination.(*int) = r
|
||||
case "*float64":
|
||||
// defaults to float64
|
||||
r := gooconf.Float(vals[i].EnvVars[j])
|
||||
*vals[i].Destination.(*float64) = r
|
||||
default:
|
||||
// it is unlikely we will ever get here. Let this serve more as a runtime check for when debugging.
|
||||
return fmt.Errorf("invalid type for env var: `%v`", vals[i].EnvVars[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user