mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-02 01:28:13 -05:00
fix netip parsing (#20)
This commit is contained in:
parent
238ec25314
commit
f853cd9ec9
@ -58,14 +58,14 @@ func BinaryToIPString(b []byte) string {
|
|||||||
func GetIPFromHeader(headerValue string) (string, error) {
|
func GetIPFromHeader(headerValue string) (string, error) {
|
||||||
a := strings.Split(headerValue, ",")
|
a := strings.Split(headerValue, ",")
|
||||||
h := strings.TrimSpace(a[len(a)-1])
|
h := strings.TrimSpace(a[len(a)-1])
|
||||||
ip, err := netip.ParseAddrPort(h)
|
ip, err := netip.ParseAddr(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if !ip.IsValid() {
|
if !ip.IsValid() {
|
||||||
return "", errors.New("invalid ip")
|
return "", errors.New("invalid ip")
|
||||||
}
|
}
|
||||||
return ip.Addr().String(), nil
|
return ip.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SplitIPAddr 传入/分割的v4v6混合地址,返回v4和v6地址与有效地址
|
// SplitIPAddr 传入/分割的v4v6混合地址,返回v4和v6地址与有效地址
|
||||||
|
Loading…
Reference in New Issue
Block a user