1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-15 07:23:37 -04:00
v2fly/infra/conf/geodata/memconservative/memc.go
2022-01-02 15:16:23 +00:00

42 lines
1.2 KiB
Go

package memconservative
import (
"runtime"
"github.com/v2fly/v2ray-core/v5/app/router/routercommon"
"github.com/v2fly/v2ray-core/v5/infra/conf/geodata"
)
//go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen
type memConservativeLoader struct {
geoipcache GeoIPCache
geositecache GeoSiteCache
}
func (m *memConservativeLoader) LoadIP(filename, country string) ([]*routercommon.CIDR, error) {
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) {
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)}
}
func init() {
geodata.RegisterGeoDataLoaderImplementationCreator("memconservative", newMemConservativeLoader)
}