From bf0e7e35c860843f0237aa28242db1a5dfcd332a Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Tue, 4 May 2021 11:28:34 +0100 Subject: [PATCH] move geo loader conf to environment variable --- infra/conf/dns.go | 12 ++++++------ infra/conf/router.go | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/infra/conf/dns.go b/infra/conf/dns.go index af3b048bb..56b27581e 100644 --- a/infra/conf/dns.go +++ b/infra/conf/dns.go @@ -6,6 +6,8 @@ import ( "sort" "strings" + "github.com/v2fly/v2ray-core/v4/common/platform" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/geodata" rule2 "github.com/v2fly/v2ray-core/v4/infra/conf/rule" @@ -140,8 +142,6 @@ type DNSConfig struct { QueryStrategy string `json:"queryStrategy"` DisableCache bool `json:"disableCache"` DisableFallback bool `json:"disableFallback"` - - GeoLoader string `json:"geoLoader"` } type HostAddress struct { @@ -194,11 +194,11 @@ func getHostMapping(ha *HostAddress) *dns.Config_HostMapping { func (c *DNSConfig) Build() (*dns.Config, error) { cfgctx := cfgcommon.NewConfigureLoadingContext(context.Background()) - if c.GeoLoader == "" { - c.GeoLoader = "standard" - } + geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string { + return "standard" + }) - if loader, err := geodata.GetGeoDataLoader(c.GeoLoader); err == nil { + if loader, err := geodata.GetGeoDataLoader(geoloadername); err == nil { cfgcommon.SetGeoDataLoader(cfgctx, loader) } else { return nil, newError("unable to create geo data loader ").Base(err) diff --git a/infra/conf/router.go b/infra/conf/router.go index d9f65c6ae..fef67a7de 100644 --- a/infra/conf/router.go +++ b/infra/conf/router.go @@ -5,6 +5,8 @@ import ( "encoding/json" "strings" + "github.com/v2fly/v2ray-core/v4/common/platform" + "github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon" "github.com/v2fly/v2ray-core/v4/infra/conf/geodata" rule2 "github.com/v2fly/v2ray-core/v4/infra/conf/rule" @@ -61,7 +63,6 @@ type RouterConfig struct { Balancers []*BalancingRule `json:"balancers"` DomainMatcher string `json:"domainMatcher"` - GeoLoader string `json:"geoLoader"` } func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy { @@ -90,11 +91,11 @@ func (c *RouterConfig) Build() (*router.Config, error) { cfgctx := cfgcommon.NewConfigureLoadingContext(context.Background()) - if c.GeoLoader == "" { - c.GeoLoader = "standard" - } + geoloadername := platform.NewEnvFlag("v2ray.conf.geoloader").GetValue(func() string { + return "standard" + }) - if loader, err := geodata.GetGeoDataLoader(c.GeoLoader); err == nil { + if loader, err := geodata.GetGeoDataLoader(geoloadername); err == nil { cfgcommon.SetGeoDataLoader(cfgctx, loader) } else { return nil, newError("unable to create geo data loader ").Base(err)