Same as last
This commit is contained in:
parent
09d000a1d5
commit
7270bd057e
3 changed files with 6 additions and 14 deletions
13
index.go
13
index.go
|
@ -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
|
||||
|
|
6
main.go
6
main.go
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue