mirror of
https://github.com/eosswedenorg/thalos
synced 2026-06-16 04:24:56 +02:00
cmd/thalos/server.go: define and use ReadConfig() that utilizes Config.ReadFile and Config.ReadCliFlags() methods
This commit is contained in:
parent
4a5cff20cd
commit
457e0e4eeb
1 changed files with 16 additions and 10 deletions
|
|
@ -7,7 +7,6 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
|
@ -223,6 +222,20 @@ func stateSaver(state app.State) error {
|
|||
return cache.Set(ctx, "state", state, 0)
|
||||
}
|
||||
|
||||
func ReadConfig(cfg *config.Config, ctx *cli.Context) error {
|
||||
// Read file first.
|
||||
if err := cfg.ReadFile(ctx.Path("config")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Then override any cli flags
|
||||
if err := cfg.ReadCliFlags(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func serverCmd(ctx *cli.Context) error {
|
||||
var err error
|
||||
var chainInfo *eos.InfoResp
|
||||
|
|
@ -242,15 +255,8 @@ func serverCmd(ctx *cli.Context) error {
|
|||
|
||||
// Parse config
|
||||
conf = config.New()
|
||||
if err = conf.ReadFile(ctx.Path("config")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If log file is given on the commandline, override config values.
|
||||
logFile := ctx.Path("log")
|
||||
if len(logFile) > 0 {
|
||||
conf.Log.Directory = path.Dir(logFile)
|
||||
conf.Log.Filename = path.Base(logFile)
|
||||
if err = ReadConfig(&conf, ctx); err != nil {
|
||||
return fmt.Errorf("config: %s", err)
|
||||
}
|
||||
|
||||
lvl, err := log.ParseLevel(ctx.String("level"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue