瀏覽代碼

refactor(config): move common fields into single table

ayn2op 1 年之前
父節點
當前提交
b395d938c4
共有 2 個文件被更改,包括 31 次插入24 次删除
  1. 5 5
      cmd/state.go
  2. 26 19
      internal/config/config.go

+ 5 - 5
cmd/state.go

@@ -20,18 +20,18 @@ type State struct {
 }
 
 func openState(token string) error {
-	api.UserAgent = app.cfg.UserAgent
+	api.UserAgent = app.cfg.Identify.UserAgent
 	gateway.DefaultIdentity = gateway.IdentifyProperties{
 		OS:     runtime.GOOS,
 		Device: "",
 
-		Browser:          app.cfg.Browser,
-		BrowserVersion:   app.cfg.BrowserVersion,
-		BrowserUserAgent: app.cfg.UserAgent,
+		Browser:          app.cfg.Identify.Browser,
+		BrowserVersion:   app.cfg.Identify.BrowserVersion,
+		BrowserUserAgent: app.cfg.Identify.UserAgent,
 	}
 
 	gateway.DefaultPresence = &gateway.UpdatePresenceCommand{
-		Status: app.cfg.Status,
+		Status: app.cfg.Identify.Status,
 	}
 
 	discordState = &State{

+ 26 - 19
internal/config/config.go

@@ -13,25 +13,30 @@ import (
 
 const fileName = "config.toml"
 
-type Config struct {
-	Mouse  bool   `toml:"mouse"`
-	Editor string `toml:"editor"`
+type (
+	Identify struct {
+		Status         discord.Status `toml:"status"`
+		Browser        string         `toml:"browser"`
+		BrowserVersion string         `toml:"browser_version"`
+		UserAgent      string         `toml:"user_agent"`
+	}
 
-	HideBlockedUsers    bool  `toml:"hide_blocked_users"`
-	ShowAttachmentLinks bool  `toml:"show_attachment_links"`
-	MessagesLimit       uint8 `toml:"messages_limit"`
+	Config struct {
+		Mouse  bool   `toml:"mouse"`
+		Editor string `toml:"editor"`
 
-	Timestamps       bool   `toml:"timestamps"`
-	TimestampsFormat string `toml:"timestamps_format"`
+		HideBlockedUsers    bool  `toml:"hide_blocked_users"`
+		ShowAttachmentLinks bool  `toml:"show_attachment_links"`
+		MessagesLimit       uint8 `toml:"messages_limit"`
 
-	Status         discord.Status `toml:"status"`
-	Browser        string         `toml:"browser"`
-	BrowserVersion string         `toml:"browser_version"`
-	UserAgent      string         `toml:"user_agent"`
+		Timestamps       bool   `toml:"timestamps"`
+		TimestampsFormat string `toml:"timestamps_format"`
 
-	Keys  Keys  `toml:"keys"`
-	Theme Theme `toml:"theme"`
-}
+		Identify Identify `toml:"identify"`
+		Keys     Keys     `toml:"keys"`
+		Theme    Theme    `toml:"theme"`
+	}
+)
 
 func defaultConfig() *Config {
 	return &Config{
@@ -45,10 +50,12 @@ func defaultConfig() *Config {
 		Timestamps:       false,
 		TimestampsFormat: time.Kitchen,
 
-		Status:         discord.OnlineStatus,
-		Browser:        consts.Browser,
-		BrowserVersion: consts.BrowserVersion,
-		UserAgent:      consts.UserAgent,
+		Identify: Identify{
+			Status:         discord.OnlineStatus,
+			Browser:        consts.Browser,
+			BrowserVersion: consts.BrowserVersion,
+			UserAgent:      consts.UserAgent,
+		},
 
 		Keys:  defaultKeys(),
 		Theme: defaultTheme(),