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
This commit is contained in:
zpencer 2018-08-09 13:21:54 -07:00 committed by GitHub
parent 851a674d9b
commit 2d5ed88f1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 22 deletions

View File

@ -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))
}