diff --git a/internal/server/config.go b/internal/server/config.go index d5d9030b..b7355900 100644 --- a/internal/server/config.go +++ b/internal/server/config.go @@ -71,14 +71,13 @@ func loadConfig(path string) (*Config, error) { var json string data, err := ioutil.ReadFile(path) if err != nil { - if os.IsNotExist(err) { - json = `{"` + ServerID + `":"` + randomKey(16) + `"}` - } else { + if !os.IsNotExist(err) { return nil, err } } else { json = string(data) } + config := &Config{ path: path, _followHost: gjson.Get(json, FollowHost).String(), @@ -96,6 +95,10 @@ func loadConfig(path string) (*Config, error) { _logConfig: gjson.Get(json, LogConfig).String(), } + if config._serverID == "" { + config._serverID = randomKey(16) + } + // load properties if err := config.setProperty(RequirePass, config._requirePassP, true); err != nil { return nil, err @@ -191,7 +194,9 @@ func (config *Config) write(writeProperties bool) { if config._logConfigP != "" { var lcfg map[string]interface{} json.Unmarshal([]byte(config._logConfig), &lcfg) - m[LogConfig] = lcfg + if len(lcfg) > 0 { + m[LogConfig] = lcfg + } } data, err := json.MarshalIndent(m, "", "\t") if err != nil {