refactor: initialize default config when file is empty

This commit is contained in:
ayntgl 2022-01-09 23:18:03 +04:00
parent 61cf6f7383
commit d815c77c29
2 changed files with 3 additions and 3 deletions

View file

@ -78,12 +78,13 @@ func (c *Config) Load() {
e := json.NewEncoder(f)
e.SetIndent("", "\t")
c = New()
err = e.Encode(c)
if err != nil {
panic(err)
}
} else {
err = json.NewDecoder(f).Decode(&c)
err = json.NewDecoder(f).Decode(c)
if err != nil {
panic(err)
}

View file

@ -22,7 +22,7 @@ type App struct {
Session *discordgo.Session
SelectedChannel *discordgo.Channel
SelectedMessage int
Config *config.Config
Config config.Config
}
func NewApp() *App {
@ -37,7 +37,6 @@ func NewApp() *App {
Session: s,
SelectedMessage: -1,
Config: config.New(),
}
}