fix(util): return default config if os.UserHomeDir() returns err

This commit is contained in:
rigormorrtiss 2021-08-29 11:33:37 +04:00
parent d7c0fbb303
commit 56b4f74dff

View file

@ -17,15 +17,15 @@ type Config struct {
// NewConfig reads the configuration file (if exists) and returns a new config.
func NewConfig() *Config {
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
c := Config{
Mouse: true,
GetMessagesLimit: 50,
}
userHomeDir, err := os.UserHomeDir()
if err != nil {
return &c
}
configPath := userHomeDir + "/.config/discordo/config.json"
if _, err := os.Stat(configPath); os.IsNotExist(err) {
return &c