diff --git a/cmd/go-temper/httpServer.go b/cmd/go-temper/httpServer.go index 480cf1d..51d8486 100644 --- a/cmd/go-temper/httpServer.go +++ b/cmd/go-temper/httpServer.go @@ -1,11 +1,14 @@ package main import ( + "bytes" "log" - "net/http" "strconv" "time" + "html/template" + "net/http" + "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -30,10 +33,7 @@ func httpServer(host string, port int) { IdleTimeout: time.Duration(config.WebSrvIdleTimeout) * time.Second, } - path.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - httpAccessLog(r) - w.Write([]byte("web-root")) - }) + path.HandleFunc("/", webRoot) path.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) { httpAccessLog(r) crossSiteOrigin(w) @@ -44,3 +44,25 @@ func httpServer(host string, port int) { log.Fatalf("[ERROR] %s\n", err) } } + +func webRoot(w http.ResponseWriter, r *http.Request) { + outputData := struct { + Title string + ErrorCode int + }{ + Title: "forbidden", + ErrorCode: http.StatusForbidden, + } + + tmplt, err := template.New("webRoot").Parse(webErrorTmplt()) + if err != nil { + log.Fatalf("[FATAL] Unable to parse webRoot template: %v\n", err) + } + + var output bytes.Buffer + if err := tmplt.Execute(&output, outputData); err != nil { + log.Fatalf("[FATAL] Unable to process webRoot template: %v\n", err) + } + + w.Write(output.Bytes()) +} diff --git a/cmd/go-temper/httpTemplates.go b/cmd/go-temper/httpTemplates.go new file mode 100644 index 0000000..22a363f --- /dev/null +++ b/cmd/go-temper/httpTemplates.go @@ -0,0 +1,43 @@ +package main + +func webErrorTmplt() string { + return ` + +
+ +