Skip to content

Commit

Permalink
Merge pull request #94 from DOCCA0/main
Browse files Browse the repository at this point in the history
ipv6本地地址上传图片报错
  • Loading branch information
rocboss authored Jun 12, 2022
2 parents 6b23c6e + 9cf6560 commit 087c6d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/util/iploc/iploc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ const (

// Find get country and city base ip
func Find(ip string) (string, string) {
offset := searchIndex(binary.BigEndian.Uint32(net.ParseIP(ip).To4()))
// If ip is "::1", To4 returns nil.
to4 := net.ParseIP(ip).To4()
if to4 == nil {
to4 = net.ParseIP("127.0.0.1").To4()
}
offset := searchIndex(binary.BigEndian.Uint32(to4))
if offset <= 0 {
return "", ""
}
Expand Down

0 comments on commit 087c6d2

Please sign in to comment.