github.com/metacubex/mihomo@v1.18.5/component/geodata/memconservative/memc.go (about) 1 package memconservative 2 3 import ( 4 "errors" 5 "fmt" 6 "runtime" 7 8 "github.com/metacubex/mihomo/component/geodata" 9 "github.com/metacubex/mihomo/component/geodata/router" 10 ) 11 12 type memConservativeLoader struct { 13 geoipcache GeoIPCache 14 geositecache GeoSiteCache 15 } 16 17 func (m *memConservativeLoader) LoadIPByPath(filename, country string) ([]*router.CIDR, error) { 18 defer runtime.GC() 19 geoip, err := m.geoipcache.Unmarshal(filename, country) 20 if err != nil { 21 return nil, fmt.Errorf("failed to decode geodata file: %s, base error: %s", filename, err.Error()) 22 } 23 return geoip.Cidr, nil 24 } 25 26 func (m *memConservativeLoader) LoadIPByBytes(geoipBytes []byte, country string) ([]*router.CIDR, error) { 27 return nil, errors.New("memConservative do not support LoadIPByBytes") 28 } 29 30 func (m *memConservativeLoader) LoadSiteByPath(filename, list string) ([]*router.Domain, error) { 31 defer runtime.GC() 32 geosite, err := m.geositecache.Unmarshal(filename, list) 33 if err != nil { 34 return nil, fmt.Errorf("failed to decode geodata file: %s, base error: %s", filename, err.Error()) 35 } 36 return geosite.Domain, nil 37 } 38 39 func (m *memConservativeLoader) LoadSiteByBytes(geositeBytes []byte, list string) ([]*router.Domain, error) { 40 return nil, errors.New("memConservative do not support LoadSiteByBytes") 41 } 42 43 func newMemConservativeLoader() geodata.LoaderImplementation { 44 return &memConservativeLoader{make(map[string]*router.GeoIP), make(map[string]*router.GeoSite)} 45 } 46 47 func init() { 48 geodata.RegisterGeoDataLoaderImplementationCreator("memconservative", newMemConservativeLoader) 49 }