William Petit
74928fe413
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
33 lines
674 B
Go
33 lines
674 B
Go
package common
|
|
|
|
import (
|
|
"forge.cadoles.com/cadoles/bouncer/internal/config"
|
|
"github.com/pkg/errors"
|
|
"github.com/urfave/cli/v2"
|
|
"gitlab.com/wpetit/goweb/logger"
|
|
)
|
|
|
|
func LoadConfig(ctx *cli.Context) (*config.Config, error) {
|
|
configFile := ctx.String("config")
|
|
|
|
var (
|
|
conf *config.Config
|
|
err error
|
|
)
|
|
|
|
if configFile != "" {
|
|
logger.Info(ctx.Context, "loading config", logger.F("config", configFile))
|
|
|
|
conf, err = config.NewFromFile(configFile)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "Could not load config file '%s'", configFile)
|
|
}
|
|
} else {
|
|
logger.Info(ctx.Context, "using default config")
|
|
|
|
conf = config.NewDefault()
|
|
}
|
|
|
|
return conf, nil
|
|
}
|