1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 09:26:21 -05:00
v2fly/infra/conf/geodata/memconservative/memc.go

42 lines
1.2 KiB
Go
Raw Normal View History

2021-05-04 06:19:03 -04:00
package memconservative
import (
2021-05-04 06:21:49 -04:00
"runtime"
"github.com/v2fly/v2ray-core/v5/app/router/routercommon"
"github.com/v2fly/v2ray-core/v5/infra/conf/geodata"
2021-05-04 06:19:03 -04:00
)
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
2021-05-04 06:19:03 -04:00
type memConservativeLoader struct {
geoipcache GeoIPCache
geositecache GeoSiteCache
}
func (m *memConservativeLoader) LoadIP(filename, country string) ([]*routercommon.CIDR, error) {
2021-05-04 06:19:03 -04:00
defer runtime.GC()
geoip, err := m.geoipcache.Unmarshal(filename, country)
if err != nil {
return nil, newError("failed to decode geodata file: ", filename).Base(err)
}
return geoip.Cidr, nil
}
func (m *memConservativeLoader) LoadSite(filename, list string) ([]*routercommon.Domain, error) {
2021-05-04 06:19:03 -04:00
defer runtime.GC()
geosite, err := m.geositecache.Unmarshal(filename, list)
if err != nil {
return nil, newError("failed to decode geodata file: ", filename).Base(err)
}
return geosite.Domain, nil
}
func newMemConservativeLoader() geodata.LoaderImplementation {
return &memConservativeLoader{make(map[string]*routercommon.GeoIP), make(map[string]*routercommon.GeoSite)}
2021-05-04 06:19:03 -04:00
}
func init() {
2021-05-04 06:21:49 -04:00
geodata.RegisterGeoDataLoaderImplementationCreator("memconservative", newMemConservativeLoader)
2021-05-04 06:19:03 -04:00
}