clash/component/geodata/geodata.go

45 lines
1 KiB
Go
Raw Normal View History

2021-11-17 08:03:47 +00:00
package geodata
import (
"fmt"
2023-11-03 13:01:45 +00:00
"github.com/metacubex/mihomo/component/geodata/router"
C "github.com/metacubex/mihomo/constant"
2021-11-17 08:03:47 +00:00
)
type loader struct {
LoaderImplementation
}
func (l *loader) LoadGeoSite(list string) ([]*router.Domain, error) {
2023-03-23 10:58:24 +00:00
return l.LoadSiteByPath(C.GeositeName, list)
2021-11-17 08:03:47 +00:00
}
func (l *loader) LoadGeoIP(country string) ([]*router.CIDR, error) {
2022-06-03 08:50:05 +00:00
return l.LoadIPByPath(C.GeoipName, country)
2021-11-17 08:03:47 +00:00
}
var loaders map[string]func() LoaderImplementation
func RegisterGeoDataLoaderImplementationCreator(name string, loader func() LoaderImplementation) {
if loaders == nil {
loaders = map[string]func() LoaderImplementation{}
}
loaders[name] = loader
}
func getGeoDataLoaderImplementation(name string) (LoaderImplementation, error) {
if geoLoader, ok := loaders[name]; ok {
return geoLoader(), nil
}
return nil, fmt.Errorf("unable to locate GeoData loader %s", name)
}
func GetGeoDataLoader(name string) (Loader, error) {
loadImpl, err := getGeoDataLoaderImplementation(name)
if err == nil {
return &loader{loadImpl}, nil
}
return nil, err
}