NAT64 的机器一直报 IP 变更,加忽略!

This commit is contained in:
naiba
2021-04-07 21:11:59 +08:00
parent 40b9ffd042
commit 330015290f
7 changed files with 46 additions and 20 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
@@ -33,8 +35,10 @@ type Config struct {
HTTPPort uint
GRPCPort uint
EnableIPChangeNotification bool
IgnoredIPNotification string // 忽略IP变更提醒的服务器列表
v *viper.Viper
v *viper.Viper
IgnoredIPNotificationServerIDs map[uint64]struct{}
}
func (c *Config) Read(path string) error {
@@ -54,6 +58,8 @@ func (c *Config) Read(path string) error {
c.Site.Theme = "default"
}
c.updateIgnoredIPNotificationID()
c.v.OnConfigChange(func(in fsnotify.Event) {
c.v.Unmarshal(c)
fmt.Println("配置文件更新,重载配置", c)
@@ -63,7 +69,19 @@ func (c *Config) Read(path string) error {
return nil
}
func (c *Config) updateIgnoredIPNotificationID() {
c.IgnoredIPNotificationServerIDs = make(map[uint64]struct{})
splitedIDs := strings.Split(c.IgnoredIPNotification, ",")
for i := 0; i < len(splitedIDs); i++ {
id, _ := strconv.ParseUint(splitedIDs[i], 10, 64)
if id > 0 {
c.IgnoredIPNotificationServerIDs[id] = struct{}{}
}
}
}
func (c *Config) Save() error {
c.updateIgnoredIPNotificationID()
data, err := yaml.Marshal(c)
if err != nil {
return err