goCake/main.go

31 lines
718 B
Go
Raw Normal View History

2020-11-08 16:00:33 +00:00
package main
import (
"html/template"
"net/http"
)
func main() {
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
// when navigating to /home it should serve the home page
2020-11-15 19:46:32 +00:00
http.HandleFunc("/", Home)
http.HandleFunc("/rewards", CakeRewards)
http.HandleFunc("/table", CakeRewards)
http.ListenAndServe(":8080", nil)
2020-11-08 16:00:33 +00:00
}
func render(w http.ResponseWriter, tmpl string, data interface{}) {
//parse the template file held in the templates folder
t, err := template.ParseFiles("templates/"+tmpl, "templates/includes.html")
if err != nil {
panic(err)
}
// render the website and pass data to the templating engine
err = t.Execute(w, data)
if err != nil {
panic(err)
}
}