refactor: Geodata initialization

This commit is contained in:
H1JK
2023-08-06 23:34:10 +08:00
parent cca701c641
commit 68bf6f16ac
2 changed files with 9 additions and 22 deletions

View File

@@ -2,7 +2,6 @@ package config
import (
"fmt"
"github.com/Dreamacro/clash/component/geodata"
"os"
C "github.com/Dreamacro/clash/constant"
@@ -28,23 +27,6 @@ func Init(dir string) error {
f.Write([]byte(`mixed-port: 7890`))
f.Close()
}
buf, _ := os.ReadFile(C.Path.Config())
rawCfg, err := UnmarshalRawConfig(buf)
if err != nil {
log.Errorln(err.Error())
fmt.Printf("configuration file %s test failed\n", C.Path.Config())
os.Exit(1)
}
if !C.GeodataMode {
C.GeodataMode = rawCfg.GeodataMode
}
C.GeoIpUrl = rawCfg.GeoXUrl.GeoIp
C.GeoSiteUrl = rawCfg.GeoXUrl.GeoSite
C.MmdbUrl = rawCfg.GeoXUrl.Mmdb
// initial GeoIP
if err := geodata.InitGeoIP(); err != nil {
return fmt.Errorf("can't initial GeoIP: %w", err)
}
return nil
}