Fix: read geoip and geosite in config file (#359)

Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
This commit is contained in:
Sousa Chinensis
2021-06-04 10:42:15 +08:00
committed by GitHub
co-authored by loyalsoldier
parent 068d23371c
commit 07fec5eb26
2 changed files with 11 additions and 4 deletions
+9 -2
View File
@@ -34,9 +34,16 @@ func GetProgramDir() string {
}
func GetAssetLocation(file string) string {
if filepath.IsAbs(file) {
return file
}
if loc := os.Getenv("TROJAN_GO_LOCATION_ASSET"); loc != "" {
log.Debugf("env set: TROJAN_GO_LOCATION_ASSET=%s", loc)
return filepath.Join(loc, file)
absPath, err := filepath.Abs(loc)
if err != nil {
log.Fatal(err)
}
log.Debugf("env set: TROJAN_GO_LOCATION_ASSET=%s", absPath)
return filepath.Join(absPath, file)
}
return filepath.Join(GetProgramDir(), file)
}
+2 -2
View File
@@ -312,7 +312,7 @@ func NewClient(ctx context.Context, underlay tunnel.Client) (*Client, error) {
ipCode := loadCode(cfg, "geoip:")
for _, c := range ipCode {
code := c.code
cidrs, err := geodataLoader.LoadGeoIP(code)
cidrs, err := geodataLoader.LoadIP(cfg.Router.GeoIPFilename, code)
if err != nil {
log.Error(err)
} else {
@@ -341,7 +341,7 @@ func NewClient(ctx context.Context, underlay tunnel.Client) (*Client, error) {
continue
}
domainList, err := geodataLoader.LoadGeoSite(code)
domainList, err := geodataLoader.LoadSite(cfg.Router.GeoSiteFilename, code)
if err != nil {
log.Error(err)
} else {