修复IPv6访问可能导致进程异常退出的Bug

This commit is contained in:
GoEdgeLab
2021-08-01 09:20:07 +08:00
parent 19e03abf0b
commit 678e7f2c2a
2 changed files with 5 additions and 4 deletions

View File

@@ -1,12 +1,13 @@
package iplibrary package iplibrary
type LibraryInterface interface { type LibraryInterface interface {
// 加载数据库文件 // Load 加载数据库文件
Load(dbPath string) error Load(dbPath string) error
// 查询IP // Lookup 查询IP
// 返回结果有可能为空
Lookup(ip string) (*Result, error) Lookup(ip string) (*Result, error)
// 关闭数据库文件 // Close 关闭数据库文件
Close() Close()
} }

View File

@@ -165,7 +165,7 @@ Loop:
ip := ipString[atIndex+1:] ip := ipString[atIndex+1:]
if iplibrary.SharedLibrary != nil { if iplibrary.SharedLibrary != nil {
result, err := iplibrary.SharedLibrary.Lookup(ip) result, err := iplibrary.SharedLibrary.Lookup(ip)
if err == nil { if err == nil && result != nil {
this.cityMap[serverId+"@"+result.Country+"@"+result.Province+"@"+result.City] ++ this.cityMap[serverId+"@"+result.Country+"@"+result.Province+"@"+result.City] ++
if len(result.ISP) > 0 { if len(result.ISP) > 0 {