Эх сурвалжийг харах

refactor: initialize default config when file is empty

ayntgl 4 жил өмнө
parent
commit
d815c77c29
2 өөрчлөгдсөн 3 нэмэгдсэн , 3 устгасан
  1. 2 1
      config/mod.go
  2. 1 2
      ui/app.go

+ 2 - 1
config/mod.go

@@ -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)
 		}

+ 1 - 2
ui/app.go

@@ -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(),
 	}
 }