evilthings/index.go
Samantha Becker caabd6d740 App stuff
2023-09-18 11:15:19 +02:00

34 lines
782 B
Go

package main
import (
"html/template"
"net/http"
"time"
)
var index_template *template.Template
type indexData struct {
Time string
}
func handleRoot(w http.ResponseWriter, r *http.Request) {
//if index_template == nil {
// tmpl, err := template.ParseFiles("templates/index.html")
// if err != nil {
// http.Error(w, "Couldn't parse template file", http.StatusInternalServerError)
// return
// }
// index_template = tmpl
//}
tmpl, err := template.ParseFiles("templates/index.html")
if err != nil {
http.Error(w, "Couldn't parse template file", http.StatusInternalServerError)
return
}
err = tmpl.Execute(w, indexData{Time: time.Now().Format(time.Stamp)})
if err != nil {
http.Error(w, "Failed to execute template", http.StatusInternalServerError)
}
}