Просмотр исходного кода

Defer-close the newly created config file (if does not exist)

ayntgl 4 лет назад
Родитель
Сommit
7d2dd4652f
1 измененных файлов с 3 добавлено и 0 удалено
  1. 3 0
      util/config.go

+ 3 - 0
util/config.go

@@ -45,6 +45,7 @@ func LoadConfig() *Config {
 		if err != nil {
 			panic(err)
 		}
+		defer f.Close()
 
 		c := Config{
 			Mouse:         true,
@@ -80,6 +81,8 @@ func LoadConfig() *Config {
 		}
 
 		f.Sync()
+
+		return &c
 	}
 
 	d, err := os.ReadFile(configPath)