github.com/yaling888/clash@v1.53.0/component/geodata/memconservative/memc.go (about) 1 package memconservative 2 3 import ( 4 "fmt" 5 "runtime" 6 7 "github.com/yaling888/clash/component/geodata" 8 "github.com/yaling888/clash/component/geodata/router" 9 ) 10 11 type memConservativeLoader struct { 12 geoipcache GeoIPCache 13 geositecache GeoSiteCache 14 } 15 16 func (m *memConservativeLoader) LoadIP(filename, country string) ([]*router.CIDR, error) { 17 defer runtime.GC() 18 geoip, err := m.geoipcache.Unmarshal(filename, country) 19 if err != nil { 20 return nil, fmt.Errorf("failed to decode geodata file: %s, base error: %w", filename, err) 21 } 22 return geoip.Cidr, nil 23 } 24 25 func (m *memConservativeLoader) LoadSite(filename, list string) ([]*router.Domain, error) { 26 defer runtime.GC() 27 geosite, err := m.geositecache.Unmarshal(filename, list) 28 if err != nil { 29 return nil, fmt.Errorf("failed to decode geodata file: %s, base error: %w", filename, err) 30 } 31 return geosite.Domain, nil 32 } 33 34 func newMemConservativeLoader() geodata.LoaderImplementation { 35 return &memConservativeLoader{make(map[string]*router.GeoIP), make(map[string]*router.GeoSite)} 36 } 37 38 func init() { 39 geodata.RegisterGeoDataLoaderImplementationCreator("memconservative", newMemConservativeLoader) 40 }