goCake/main.go

33 lines
775 B
Go
Raw Permalink Normal View History

2020-11-08 16:00:33 +00:00
package main
import (
2021-01-16 14:13:12 +00:00
"fmt"
2020-11-08 16:00:33 +00:00
"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)
2020-11-22 17:33:27 +00:00
http.HandleFunc("/rewards", Rewards)
http.HandleFunc("/kraken", Rewards)
2021-01-16 14:13:12 +00:00
fmt.Println("Starting server on http://localhost:8080")
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)
}
}