From 2d5ed88f1c6f495497a20554aeed4e56847e72b5 Mon Sep 17 00:00:00 2001 From: zpencer Date: Thu, 9 Aug 2018 13:21:54 -0700 Subject: [PATCH] grpc-zpages: clarify statics assets start up message (#308) The message right now is confusing, and may lead to users navigating here instead of the envoy port. Ran gofmt move flags to pkg level, avoid http mux --- .../static-assets/static_assets_server.go | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/grpc-zpages/docker/static-assets/static_assets_server.go b/grpc-zpages/docker/static-assets/static_assets_server.go index ded6c6d..f007f14 100644 --- a/grpc-zpages/docker/static-assets/static_assets_server.go +++ b/grpc-zpages/docker/static-assets/static_assets_server.go @@ -1,29 +1,30 @@ package main import ( - "flag" - "fmt" - "log" - "net/http" - "path" - "strings" + "flag" + "fmt" + "log" + "net/http" + "path" + "strings" ) -func main() { - var port = flag.Int("port", 8080, "local port") - var wwwRoot = flag.String("wwwroot", "/www", "root for http files") - flag.Parse() +var port = flag.Int("port", 8080, "local port") +var wwwRoot = flag.String("wwwroot", "/www", "root for http files") - mux := http.NewServeMux() - mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Printf("Got request %s\n", r.URL.Path) - localPath := path.Join(*wwwRoot, r.URL.Path[1:]) - if (strings.HasSuffix(localPath, ".css") || strings.HasSuffix(localPath, ".js")) { - http.ServeFile(w, r, localPath) - } else { - http.ServeFile(w, r, path.Join(*wwwRoot, "dist_channelz/index.html")) - } - }) - fmt.Printf("Starting server on port %d...\n", *port) - log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), mux)) +func main() { + flag.Parse() + + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + fmt.Printf("Got request %s\n", r.URL.Path) + localPath := path.Join(*wwwRoot, r.URL.Path[1:]) + if strings.HasSuffix(localPath, ".css") || strings.HasSuffix(localPath, ".js") { + http.ServeFile(w, r, localPath) + } else { + http.ServeFile(w, r, path.Join(*wwwRoot, "dist_channelz/index.html")) + } + }) + fmt.Printf("Starting static assets server on port %d . Note this is not the envoy port!\n"+ + "You should not need to look at this port unless you know what you're doing.\n", *port) + log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), nil)) }