fix: geoip mmdb/geodata init

This commit is contained in:
metacubex
2023-01-09 21:07:31 +08:00
parent b4503908df
commit e9a7e104c0
6 changed files with 101 additions and 92 deletions

View File

@ -6,7 +6,6 @@ import (
var (
errPayload = errors.New("payloadRule error")
initFlag bool
noResolve = "no-resolve"
)

View File

@ -71,6 +71,11 @@ func (g *GEOIP) GetRecodeSize() int {
}
func NewGEOIP(country string, adapter string, noResolveIP bool) (*GEOIP, error) {
if err := geodata.InitGeoIP(); err != nil {
log.Errorln("can't initial GeoIP: %s", err)
return nil, err
}
if !C.GeodataMode || strings.EqualFold(country, "LAN") {
geoip := &GEOIP{
Base: &Base{},

View File

@ -50,12 +50,9 @@ func (gs *GEOSITE) GetRecodeSize() int {
}
func NewGEOSITE(country string, adapter string) (*GEOSITE, error) {
if !initFlag {
if err := geodata.InitGeoSite(); err != nil {
log.Errorln("can't initial GeoSite: %s", err)
return nil, err
}
initFlag = true
if err := geodata.InitGeoSite(); err != nil {
log.Errorln("can't initial GeoSite: %s", err)
return nil, err
}
matcher, size, err := geodata.LoadGeoSiteMatcher(country)
@ -76,4 +73,4 @@ func NewGEOSITE(country string, adapter string) (*GEOSITE, error) {
return geoSite, nil
}
//var _ C.Rule = (*GEOSITE)(nil)
var _ C.Rule = (*GEOSITE)(nil)