31 lines
718 B
Go
31 lines
718 B
Go
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
|
|
http.HandleFunc("/", Home)
|
|
http.HandleFunc("/rewards", CakeRewards)
|
|
http.HandleFunc("/table", CakeRewards)
|
|
http.ListenAndServe(":8080", nil)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|