Stop parsing proxy address (#1619)

This commit is contained in:
Asim Aslam 2020-05-12 17:38:22 +01:00 committed by GitHub
parent 762a5bc9e8
commit 116cc1e9ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -83,20 +83,23 @@ func Listen(addr string, fn func(string) (net.Listener, error)) (net.Listener, e
func Proxy(service string, address []string) (string, []string, bool) { func Proxy(service string, address []string) (string, []string, bool) {
var hasProxy bool var hasProxy bool
// get proxy // get proxy. we parse out address if present
if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 { if prx := os.Getenv("MICRO_PROXY"); len(prx) > 0 {
// default name // default name
if prx == "service" { if prx == "service" {
prx = "go.micro.proxy" prx = "go.micro.proxy"
} address = nil
service = prx
hasProxy = true
} }
// get proxy address // check if its an address
if prx := os.Getenv("MICRO_PROXY_ADDRESS"); len(prx) > 0 { if v := strings.Split(prx, ":"); len(v) > 1 {
address = []string{prx} address = []string{prx}
}
service = prx
hasProxy = true hasProxy = true
return service, address, hasProxy
} }
if prx := os.Getenv("MICRO_NETWORK"); len(prx) > 0 { if prx := os.Getenv("MICRO_NETWORK"); len(prx) > 0 {

View File

@ -57,7 +57,6 @@ func TestProxyEnv(t *testing.T) {
} }
test("MICRO_PROXY", "service", "go.micro.proxy", "") test("MICRO_PROXY", "service", "go.micro.proxy", "")
test("MICRO_PROXY_ADDRESS", "10.0.0.1:8080", "", "10.0.0.1:8080")
test("MICRO_NETWORK", "service", "go.micro.network", "") test("MICRO_NETWORK", "service", "go.micro.network", "")
test("MICRO_NETWORK_ADDRESS", "10.0.0.1:8081", "", "10.0.0.1:8081") test("MICRO_NETWORK_ADDRESS", "10.0.0.1:8081", "", "10.0.0.1:8081")
} }