Skip to content

Commit

Permalink
Merge pull request #108 from allenporter/config-persist
Browse files Browse the repository at this point in the history
Ensure config is persisted respecting command line flag
  • Loading branch information
allenporter authored Feb 21, 2022
2 parents b13c44f + d134f4c commit ea35fae
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions storageConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ import (
"github.com/sirupsen/logrus"
)

//debug global
// Command line flag global variables
var debug bool
var configFile string

//NewStreamCore do load config file
func NewStreamCore() *StorageST {
argConfigPatch := flag.String("config", "config.json", "config patch (/etc/server/config.json or config.json)")
argDebug := flag.Bool("debug", true, "set debug mode")
debug = *argDebug
flag.BoolVar(&debug, "debug", true, "set debug mode")
flag.StringVar(&configFile, "config", "config.json", "config patch (/etc/server/config.json or config.json)")
flag.Parse()

var tmp StorageST
data, err := ioutil.ReadFile(*argConfigPatch)
data, err := ioutil.ReadFile(configFile)
if err != nil {
log.WithFields(logrus.Fields{
"module": "config",
Expand Down Expand Up @@ -70,6 +71,10 @@ func NewStreamCore() *StorageST {

//ClientDelete Delete Client
func (obj *StorageST) SaveConfig() error {
log.WithFields(logrus.Fields{
"module": "config",
"func": "NewStreamCore",
}).Debugln("Saving configuration to", configFile)
v2, err := version.NewVersion("2.0.0")
if err != nil {
return err
Expand All @@ -85,8 +90,13 @@ func (obj *StorageST) SaveConfig() error {
if err != nil {
return err
}
err = ioutil.WriteFile("config.json", res, 0644)
err = ioutil.WriteFile(configFile, res, 0644)
if err != nil {
log.WithFields(logrus.Fields{
"module": "config",
"func": "SaveConfig",
"call": "WriteFile",
}).Errorln(err.Error())
return err
}
return nil
Expand Down

0 comments on commit ea35fae

Please sign in to comment.