From 9222d7715848160a542e20870c22c77b61c54dc6 Mon Sep 17 00:00:00 2001 From: Sean Porter Date: Wed, 7 Feb 2018 06:17:41 -0800 Subject: [PATCH] / hostname --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index d03ca1b..f05bac1 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "log" "net/http" + "os" "time" "github.com/gorilla/mux" @@ -14,7 +15,16 @@ var healthy = true func main() { r := mux.NewRouter() - r.Handle("/", http.FileServer(http.Dir("/www"))) + r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + hostname, err := os.Hostname() + + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } else { + w.Write([]byte(hostname)) + } + }).Methods(http.MethodGet) + r.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { if healthy { w.Write([]byte("healthy"))