github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/infra/conf/geodata/memconservative/memc.go (about) 1 package memconservative 2 3 import ( 4 "runtime" 5 6 "github.com/v2fly/v2ray-core/v5/app/router/routercommon" 7 "github.com/v2fly/v2ray-core/v5/infra/conf/geodata" 8 ) 9 10 //go:generate go run github.com/v2fly/v2ray-core/v5/common/errors/errorgen 11 12 type memConservativeLoader struct { 13 geoipcache GeoIPCache 14 geositecache GeoSiteCache 15 } 16 17 func (m *memConservativeLoader) LoadIP(filename, country string) ([]*routercommon.CIDR, error) { 18 defer runtime.GC() 19 geoip, err := m.geoipcache.Unmarshal(filename, country) 20 if err != nil { 21 return nil, newError("failed to decode geodata file: ", filename).Base(err) 22 } 23 return geoip.Cidr, nil 24 } 25 26 func (m *memConservativeLoader) LoadSite(filename, list string) ([]*routercommon.Domain, error) { 27 defer runtime.GC() 28 geosite, err := m.geositecache.Unmarshal(filename, list) 29 if err != nil { 30 return nil, newError("failed to decode geodata file: ", filename).Base(err) 31 } 32 return geosite.Domain, nil 33 } 34 35 func newMemConservativeLoader() geodata.LoaderImplementation { 36 return &memConservativeLoader{make(map[string]*routercommon.GeoIP), make(map[string]*routercommon.GeoSite)} 37 } 38 39 func init() { 40 geodata.RegisterGeoDataLoaderImplementationCreator("memconservative", newMemConservativeLoader) 41 }