mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
NAT64 的机器一直报 IP 变更,加忽略!
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user