refactor around config parsing

This commit is contained in:
A.Unger
2021-11-02 14:19:14 +01:00
parent 10731c3878
commit ab1703c2e8
5 changed files with 82 additions and 51 deletions

View File

@@ -1,6 +0,0 @@
log:
level: info
color: true
pretty: true
http:
addr: "${PROXY_HTTP_ADDR|localhost:2222}"

View File

@@ -4,8 +4,6 @@ import (
"context"
"os"
gofig "github.com/gookit/config/v2"
gooyaml "github.com/gookit/config/v2/yaml"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/version"
@@ -69,22 +67,7 @@ func NewLogger(cfg *config.Config) log.Logger {
// ParseConfig loads proxy configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
// create a new config and load files and env values onto it since this needs to be thread-safe.
cnf := gofig.NewWithOptions("proxy", gofig.ParseEnv)
// TODO(refs) add ENV + toml + json
cnf.AddDriver(gooyaml.Driver)
// TODO(refs) load from expected locations with the expected name
err := cnf.LoadFiles("/Users/aunger/code/owncloud/ocis/proxy/pkg/command/proxy_example_config.yaml")
if err != nil {
return err
}
// bind all keys to cfg, as we expect an entire proxy.[yaml, toml...] to define all keys and not only sub values.
err = cnf.BindStruct("", cfg)
return nil
return ociscfg.BindSourcesToStructs("proxy", cfg)
}
// SutureService allows for the proxy command to be embedded and supervised by a suture supervisor tree.