func pageHandler(w http.ResponseWriter, r *http.Request) { var name string var data interface{} if r.URL.Path == "/" { name = "home" } else { name = "country" slug := strings.Split(r.URL.Path, "/")[1] data = models.GetCountry(slug) } countries := models.GetCountries() t := time.Now() year := t.Format("2006") log.Printf("%i", year) pageData := PageData{ countries, data, year, } layout := path.Join("templates", "layout.html") toolbar := path.Join("templates", "_toolbar.html") page := path.Join("templates", fmt.Sprintf("%s.html", name)) tmpl, _ := template.ParseFiles(layout, page, toolbar) tmpl.ExecuteTemplate(w, "layout", &pageData) }
func countriesHandler(w http.ResponseWriter, r *http.Request) { var err error var data []models.Country defer func() { jsonResponder(w, r, data, err) }() data = models.GetCountries() }