discordo/util/config.go
2021-08-09 00:08:11 +04:00

45 lines
905 B
Go

package util
import (
"encoding/json"
"os"
)
type Theme struct {
DropDownBackground string `json:"dropdown.background"`
TreeViewBackground string `json:"treeview.background"`
TextViewBackground string `json:"textview.background"`
InputFieldBackground string `json:"inputField.background"`
}
type Config struct {
GetMessagesLimit uint `json:"getMessagesLimit"`
Theme *Theme `json:"theme"`
}
func NewConfig() *Config {
userHomeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
var config Config = Config{
GetMessagesLimit: 50,
Theme: &Theme{},
}
configPath := userHomeDir + "/.config/discordo/config.json"
if _, err := os.Stat(configPath); os.IsNotExist(err) {
return &config
}
data, err := os.ReadFile(configPath)
if err != nil {
panic(err)
}
if err = json.Unmarshal(data, &config); err != nil {
panic(err)
}
return &config
}