mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-05 03:40:01 -06:00
move config parsing in separate package for each service
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package config
|
||||
|
||||
import "github.com/owncloud/ocis/ocis-pkg/version"
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
Debug: Debug{
|
||||
@@ -15,7 +17,8 @@ func DefaultConfig() *Config {
|
||||
CacheTTL: 604800, // 7 days
|
||||
},
|
||||
Service: Service{
|
||||
Name: "web",
|
||||
Name: "web",
|
||||
Version: version.String, // TODO: ensure everywhere or remove
|
||||
},
|
||||
Tracing: Tracing{
|
||||
Enabled: false,
|
||||
|
||||
42
web/pkg/config/parser/parse.go
Normal file
42
web/pkg/config/parser/parse.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/web/pkg/config"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/config/envdecode"
|
||||
)
|
||||
|
||||
// ParseConfig loads accounts configuration from known paths.
|
||||
func ParseConfig(cfg *config.Config) error {
|
||||
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Log = &config.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil && cfg.Commons == nil {
|
||||
cfg.Log = &config.Log{}
|
||||
}
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
if err := envdecode.Decode(cfg); err != nil {
|
||||
// no environment variable set for this config is an expected "error"
|
||||
if !errors.Is(err, envdecode.ErrNoTargetFieldsAreSet) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// sanitize config
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user