优化ip2region查询代码

This commit is contained in:
刘祥超
2021-12-15 20:17:01 +08:00
parent 2b2c285c90
commit 3ff45d6f49
2 changed files with 133 additions and 4 deletions

View File

@@ -4,17 +4,16 @@ import (
"fmt"
"github.com/TeaOSLab/EdgeAPI/internal/errors"
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
"github.com/lionsoul2014/ip2region/binding/golang/ip2region"
"net"
"strings"
)
type IP2RegionLibrary struct {
db *ip2region.Ip2Region
db *IP2Region
}
func (this *IP2RegionLibrary) Load(dbPath string) error {
db, err := ip2region.New(dbPath)
db, err := NewIP2Region(dbPath)
if err != nil {
return err
}
@@ -77,6 +76,6 @@ func (this *IP2RegionLibrary) Lookup(ip string) (*Result, error) {
func (this *IP2RegionLibrary) Close() {
if this.db != nil {
this.db.Close()
return
}
}