浏览代码

Add config.new() for default configuration

ayn2op 3 年之前
父节点
当前提交
6e7bbebf44
共有 1 个文件被更改,包括 17 次插入13 次删除
  1. 17 13
      config/config.go

+ 17 - 13
config/config.go

@@ -73,19 +73,8 @@ type Config struct {
 	Theme ThemeConfig `yaml:"theme"`
 }
 
-func Load() (*Config, error) {
-	path, err := os.UserConfigDir()
-	if err != nil {
-		return nil, err
-	}
-
-	path = filepath.Join(path, Name)
-	err = os.MkdirAll(path, os.ModePerm)
-	if err != nil {
-		return nil, err
-	}
-
-	c := Config{
+func new() Config {
+	return Config{
 		Mouse:         true,
 		Timestamps:    false,
 		MessagesLimit: 50,
@@ -131,6 +120,21 @@ func Load() (*Config, error) {
 			MessageInput: MessageInputThemeConfig{},
 		},
 	}
+}
+
+func Load() (*Config, error) {
+	path, err := os.UserConfigDir()
+	if err != nil {
+		return nil, err
+	}
+
+	path = filepath.Join(path, Name)
+	err = os.MkdirAll(path, os.ModePerm)
+	if err != nil {
+		return nil, err
+	}
+
+	c := new()
 	path = filepath.Join(path, "config.yml")
 	_, err = os.Stat(path)
 	if os.IsNotExist(err) {