From 82cf7941b1f1e68e8f022b355c50e9cdc90718a3 Mon Sep 17 00:00:00 2001 From: ayntgl Date: Thu, 16 Sep 2021 08:48:58 +0400 Subject: [PATCH] refactor(util): rename NewConfig() to LoadConfig() --- discordo.go | 2 +- util/config.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/discordo.go b/discordo.go index 0ba6da6..ee05ed6 100644 --- a/discordo.go +++ b/discordo.go @@ -30,7 +30,7 @@ var ( ) func main() { - config = util.NewConfig() + config = util.LoadConfig() tview.Styles = config.Theme app = tview.NewApplication() diff --git a/util/config.go b/util/config.go index e66a700..9ce2019 100644 --- a/util/config.go +++ b/util/config.go @@ -18,9 +18,9 @@ type Config struct { Theme tview.Theme `json:"theme"` } -// NewConfig reads the configuration file (if exists) and returns a new config. -func NewConfig() *Config { - c := Config{ +// LoadConfig reads the configuration file (if exists) and returns a new config. +func LoadConfig() *Config { + c := &Config{ Token: "", Mouse: true, Notifications: true, @@ -34,11 +34,11 @@ func NewConfig() *Config { userHomeDir, err := os.UserHomeDir() if err != nil { - return &c + return c } configPath := userHomeDir + "/.config/discordo/config.json" if _, err := os.Stat(configPath); os.IsNotExist(err) { - return &c + return c } d, err := os.ReadFile(configPath) @@ -46,9 +46,9 @@ func NewConfig() *Config { panic(err) } - if err = json.Unmarshal(d, &c); err != nil { + if err = json.Unmarshal(d, c); err != nil { panic(err) } - return &c + return c }