From 8e738cd3e5a8d3994c0dc519f561f1c2afc2b507 Mon Sep 17 00:00:00 2001 From: Anton Osmond Date: Fri, 3 Aug 2018 17:10:38 +0100 Subject: [PATCH 1/2] Split SERVICE_HOST_OVERRIDE into host and port as separate vars --- lile.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lile.go b/lile.go index 665f6c6..b785bbe 100644 --- a/lile.go +++ b/lile.go @@ -113,8 +113,19 @@ func AddStreamInterceptor(sint grpc.StreamServerInterceptor) { // URLForService returns a service URL via a registry or a simple DNS name // if not available via the registry func URLForService(name string) string { - if os.Getenv("SERVICE_HOST_OVERRIDE") != "" { - return os.Getenv("SERVICE_HOST_OVERRIDE") + + var url string + port := "80" + + if val, ok := os.LookupEnv("SERVICE_HOST_OVERRIDE"); ok { + url = val + } + if val, ok := os.LookupEnv("SERVICE_PORT_OVERRIDE"); ok { + port = val + } + + if url != "" { + return fmt.Sprintf("%s:%s", url, port) } if service.Registry != nil { From 1e6718cb7809ade88a4280dd2c43a916dbd288bf Mon Sep 17 00:00:00 2001 From: Anton Osmond Date: Mon, 6 Aug 2018 11:14:37 +0100 Subject: [PATCH 2/2] Use "host" as var name to avoid shadowing the url var and don't skip the service.Registry lookup if it's enabled --- lile.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lile.go b/lile.go index b785bbe..634792c 100644 --- a/lile.go +++ b/lile.go @@ -114,20 +114,16 @@ func AddStreamInterceptor(sint grpc.StreamServerInterceptor) { // if not available via the registry func URLForService(name string) string { - var url string + host := name port := "80" if val, ok := os.LookupEnv("SERVICE_HOST_OVERRIDE"); ok { - url = val + host = val } if val, ok := os.LookupEnv("SERVICE_PORT_OVERRIDE"); ok { port = val } - if url != "" { - return fmt.Sprintf("%s:%s", url, port) - } - if service.Registry != nil { url, err := service.Registry.Get(name) if err != nil { @@ -136,7 +132,8 @@ func URLForService(name string) string { return url } - return name + ":80" + return fmt.Sprintf("%s:%s", host, port) + } // ContextClientInterceptor passes around headers for tracing and linkerd