添加代码注释+修正一个typo

This commit is contained in:
Akkia
2022-04-11 22:51:02 +08:00
parent 91a1e3fe22
commit 707985e5c8
11 changed files with 68 additions and 32 deletions

View File

@@ -48,8 +48,9 @@ func (c *AgentConfig) Save() error {
return ioutil.WriteFile(c.v.ConfigFileUsed(), data, os.ModePerm)
}
// Config 站点配置
type Config struct {
Debug bool
Debug bool // debug模式开关
Site struct {
Brand string // 站点名称
CookieName string // 浏览器 Cookie 名称
@@ -73,13 +74,14 @@ type Config struct {
EnablePlainIPInNotification bool
// IP变更提醒
Cover uint8 // 覆盖范围
IgnoredIPNotification string // 特定服务器
Cover uint8 // 覆盖范围0:提醒未被 IgnoredIPNotification 包含的所有服务器; 1:仅提醒被 IgnoredIPNotification 包含的服务器;
IgnoredIPNotification string // 特定服务器IP多个服务器用逗号分隔
v *viper.Viper
IgnoredIPNotificationServerIDs map[uint64]bool
IgnoredIPNotificationServerIDs map[uint64]bool // [ServerID] -> bool(值为true代表当前ServerID在特定服务器列表内
}
// Read 读取配置文件并应用
func (c *Config) Read(path string) error {
c.v = viper.New()
c.v.SetConfigFile(path)
@@ -101,6 +103,7 @@ func (c *Config) Read(path string) error {
return nil
}
// updateIgnoredIPNotificationID 更新用于判断服务器ID是否属于特定服务器的map
func (c *Config) updateIgnoredIPNotificationID() {
c.IgnoredIPNotificationServerIDs = make(map[uint64]bool)
splitedIDs := strings.Split(c.IgnoredIPNotification, ",")
@@ -112,6 +115,7 @@ func (c *Config) updateIgnoredIPNotificationID() {
}
}
// Save 保存配置文件
func (c *Config) Save() error {
c.updateIgnoredIPNotificationID()
data, err := yaml.Marshal(c)