2023-09-30 15:35:41 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2023-09-30 16:15:26 +00:00
|
|
|
"fmt"
|
2023-09-30 15:35:41 +00:00
|
|
|
"net/http"
|
|
|
|
|
2023-09-30 16:15:11 +00:00
|
|
|
"git.exozy.me/exozyme/status/proto"
|
2023-09-30 15:35:41 +00:00
|
|
|
"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) {
|
2023-09-30 16:15:11 +00:00
|
|
|
// get service status'
|
|
|
|
data := proto.TestServices()
|
2023-09-30 15:35:41 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2023-09-30 16:15:26 +00:00
|
|
|
|
|
|
|
fmt.Printf("Listening on http://%v/\n", "localhost:3333")
|
2023-09-30 15:35:41 +00:00
|
|
|
log.Fatal(http.ListenAndServe(":3333", nil))
|
|
|
|
}
|