6845a4e573
* minor misc changes
46 lines
929 B
Go
46 lines
929 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.exozy.me/exozyme/status/proto"
|
|
"github.com/cbroglie/mustache"
|
|
)
|
|
|
|
func parseAndRenderTemplate(templateLocation string, data interface{}) (string, error) {
|
|
tmpl, err := mustache.ParseFile(templateLocation)
|
|
if err != nil {
|
|
log.Println("Failed to parse template:", err)
|
|
return "", err
|
|
}
|
|
|
|
res, err := tmpl.Render(data)
|
|
if err != nil {
|
|
log.Println("Failed to render template:", err)
|
|
return "", err
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func rootPage(w http.ResponseWriter, r *http.Request) {
|
|
// get service status'
|
|
data := proto.TestServices()
|
|
|
|
parsedTemplate, err := parseAndRenderTemplate("templates/index.html.mustache", data)
|
|
if err != nil {
|
|
http.Error(w, err.Error(), 500)
|
|
}
|
|
|
|
w.Write([]byte(parsedTemplate))
|
|
}
|
|
|
|
func main() {
|
|
http.HandleFunc("/", rootPage)
|
|
|
|
|
|
fmt.Printf("Listening on http://%v/\n", "localhost:3333")
|
|
log.Fatal(http.ListenAndServe(":3333", nil))
|
|
}
|