Skip to content

Commit 087c6d2

Browse files
authoredJun 12, 2022
Merge pull request #94 from DOCCA0/main
ipv6本地地址上传图片报错
2 parents 6b23c6e + 9cf6560 commit 087c6d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

‎pkg/util/iploc/iploc.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ const (
2121

2222
// Find get country and city base ip
2323
func Find(ip string) (string, string) {
24-
offset := searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4()))
24+
// If ip is "::1", To4 returns nil.
25+
to4 := net.ParseIP(ip).To4()
26+
if to4 == nil {
27+
to4 = net.ParseIP("127.0.0.1").To4()
28+
}
29+
offset := searchIndex(binary.BigEndian.Uint32(to4))
2530
if offset <= 0 {
2631
return "", ""
2732
}

0 commit comments

Comments
 (0)
Please sign in to comment.