Browse Source

move geo loader conf to environment variable

Shelikhoo 4 years ago
parent
commit
bf0e7e35c8
2 changed files with 12 additions and 11 deletions
  1. 6 6
      infra/conf/dns.go
  2. 6 5
      infra/conf/router.go

+ 6 - 6
infra/conf/dns.go

@@ -6,6 +6,8 @@ import (
 	"sort"
 	"sort"
 	"strings"
 	"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/cfgcommon"
 	"github.com/v2fly/v2ray-core/v4/infra/conf/geodata"
 	"github.com/v2fly/v2ray-core/v4/infra/conf/geodata"
 	rule2 "github.com/v2fly/v2ray-core/v4/infra/conf/rule"
 	rule2 "github.com/v2fly/v2ray-core/v4/infra/conf/rule"
@@ -140,8 +142,6 @@ type DNSConfig struct {
 	QueryStrategy   string                  `json:"queryStrategy"`
 	QueryStrategy   string                  `json:"queryStrategy"`
 	DisableCache    bool                    `json:"disableCache"`
 	DisableCache    bool                    `json:"disableCache"`
 	DisableFallback bool                    `json:"disableFallback"`
 	DisableFallback bool                    `json:"disableFallback"`
-
-	GeoLoader string `json:"geoLoader"`
 }
 }
 
 
 type HostAddress struct {
 type HostAddress struct {
@@ -194,11 +194,11 @@ func getHostMapping(ha *HostAddress) *dns.Config_HostMapping {
 func (c *DNSConfig) Build() (*dns.Config, error) {
 func (c *DNSConfig) Build() (*dns.Config, error) {
 	cfgctx := cfgcommon.NewConfigureLoadingContext(context.Background())
 	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)
 		cfgcommon.SetGeoDataLoader(cfgctx, loader)
 	} else {
 	} else {
 		return nil, newError("unable to create geo data loader ").Base(err)
 		return nil, newError("unable to create geo data loader ").Base(err)

+ 6 - 5
infra/conf/router.go

@@ -5,6 +5,8 @@ import (
 	"encoding/json"
 	"encoding/json"
 	"strings"
 	"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/cfgcommon"
 	"github.com/v2fly/v2ray-core/v4/infra/conf/geodata"
 	"github.com/v2fly/v2ray-core/v4/infra/conf/geodata"
 	rule2 "github.com/v2fly/v2ray-core/v4/infra/conf/rule"
 	rule2 "github.com/v2fly/v2ray-core/v4/infra/conf/rule"
@@ -61,7 +63,6 @@ type RouterConfig struct {
 	Balancers      []*BalancingRule   `json:"balancers"`
 	Balancers      []*BalancingRule   `json:"balancers"`
 
 
 	DomainMatcher string `json:"domainMatcher"`
 	DomainMatcher string `json:"domainMatcher"`
-	GeoLoader     string `json:"geoLoader"`
 }
 }
 
 
 func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy {
 func (c *RouterConfig) getDomainStrategy() router.Config_DomainStrategy {
@@ -90,11 +91,11 @@ func (c *RouterConfig) Build() (*router.Config, error) {
 
 
 	cfgctx := cfgcommon.NewConfigureLoadingContext(context.Background())
 	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)
 		cfgcommon.SetGeoDataLoader(cfgctx, loader)
 	} else {
 	} else {
 		return nil, newError("unable to create geo data loader ").Base(err)
 		return nil, newError("unable to create geo data loader ").Base(err)