normalize webdav

This commit is contained in:
A.Unger
2021-11-08 12:32:52 +01:00
parent 185cee04e9
commit 8c2a681937
5 changed files with 23 additions and 126 deletions
-39
View File
@@ -3,14 +3,10 @@ package config
import (
"context"
"fmt"
"path"
"reflect"
"github.com/owncloud/ocis/ocis-pkg/shared"
gofig "github.com/gookit/config/v2"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
)
@@ -224,38 +220,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
}