Skip to content

Commit

Permalink
global: use net/netip
Browse files Browse the repository at this point in the history
  • Loading branch information
wdvxdr1123 committed Mar 22, 2022
1 parent 112441d commit e4d10eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
14 changes: 6 additions & 8 deletions global/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit e4d10eb

Please sign in to comment.