Same as last

This commit is contained in:
mStar aka a person 2024-01-08 16:58:43 +01:00
parent 09d000a1d5
commit 7270bd057e
3 changed files with 6 additions and 14 deletions

View file

@ -6,23 +6,12 @@ import (
"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")
tmpl, err := template.ParseFS(embed_templates, "templates/index.html")
if err != nil {
http.Error(w, "Couldn't parse template file", http.StatusInternalServerError)
return

View file

@ -1,11 +1,15 @@
package main
import (
"embed"
"log"
"net/http"
"os"
)
//go:embed templates
var embed_templates embed.FS
func main() {
port := os.Getenv("PORT")
if port == "" {
@ -14,9 +18,7 @@ func main() {
}
http.HandleFunc("/", handleRoot)
http.HandleFunc("/clicked", handleClicked)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatal(err)
}
}

View file

@ -6,6 +6,7 @@
<meta charset="UTF-8">
<title>Title</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Cantarell&display=swap');
* {
font-family: Cantarell, sans-serif;
}