diff --git a/global/fs.go b/global/fs.go index be15a5899..3c197712a 100644 --- a/global/fs.go +++ b/global/fs.go @@ -5,12 +5,11 @@ import ( "crypto/md5" "encoding/hex" "errors" - "net" + "net/netip" "net/url" "os" "path" "runtime" - "strconv" "strings" "github.com/Mrs4s/MiraiGo/utils" @@ -129,19 +128,18 @@ func DelFile(path string) bool { } // ReadAddrFile 从给定path中读取合法的IP地址与端口,每个IP地址以换行符"\n"作为分隔 -func ReadAddrFile(path string) []*net.TCPAddr { +func ReadAddrFile(path string) []netip.AddrPort { d, err := os.ReadFile(path) if err != nil { return nil } str := string(d) lines := strings.Split(str, "\n") - var ret []*net.TCPAddr + var ret []netip.AddrPort for _, l := range lines { - ip := strings.Split(strings.TrimSpace(l), ":") - if len(ip) == 2 { - port, _ := strconv.Atoi(ip[1]) - ret = append(ret, &net.TCPAddr{IP: net.ParseIP(ip[0]), Port: port}) + addr, err := netip.ParseAddrPort(l) + if err == nil { + ret = append(ret, addr) } } return ret diff --git a/go.mod b/go.mod index abf9dc248..38ab2a0da 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/Microsoft/go-winio v0.5.1 - github.com/Mrs4s/MiraiGo v0.0.0-20220321133915-aa657c0f09d0 + github.com/Mrs4s/MiraiGo v0.0.0-20220322144437-665c6acf024a github.com/RomiChan/syncx v0.0.0-20220320130821-c88644afda9c github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc github.com/fumiama/go-hide-param v0.1.4 diff --git a/go.sum b/go.sum index 95564b9e3..0b7e4b44c 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY= github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= -github.com/Mrs4s/MiraiGo v0.0.0-20220321133915-aa657c0f09d0 h1:RsFAUylRh9T4zIx4iVe8KTbG/XtI/uHw2qhhQfoCetE= -github.com/Mrs4s/MiraiGo v0.0.0-20220321133915-aa657c0f09d0/go.mod h1:APw03y3A3Qp5In9gI/S9m7DBJkWsd6FQMV+fB636bmU= +github.com/Mrs4s/MiraiGo v0.0.0-20220322144437-665c6acf024a h1:rG0RcLo/kWRAXnVLgMkudktVO2yg3kVgdV1/Zc9fwh4= +github.com/Mrs4s/MiraiGo v0.0.0-20220322144437-665c6acf024a/go.mod h1:APw03y3A3Qp5In9gI/S9m7DBJkWsd6FQMV+fB636bmU= github.com/RomiChan/protobuf v0.0.0-20220318113238-d8a99598f896 h1:UFAqSbH6VqW5mEzQV2HVB7+p3k9JfTbidWJ/9F15yz0= github.com/RomiChan/protobuf v0.0.0-20220318113238-d8a99598f896/go.mod h1:CKKOWC7mBxd36zxsCB1V8DTrwlTNRQvkSVbYqyUiGEE= github.com/RomiChan/syncx v0.0.0-20220320130821-c88644afda9c h1:zHWyqx7A71A/+mlzthPVcVrNGuTPyTpCW3meUPtaULU=