Skip to content

Instantly share code, notes, and snippets.

@cflynn07
Created February 28, 2019 09:52
Show Gist options
  • Save cflynn07/11ad6fed3cd0666f706abf04884ee31b to your computer and use it in GitHub Desktop.
Save cflynn07/11ad6fed3cd0666f706abf04884ee31b to your computer and use it in GitHub Desktop.
package handlers
import (
"html/template"
"io/ioutil"
"log"
"net/http"
)
// HomeHandler / route handler
func HomeHandler(w http.ResponseWriter, r *http.Request) {
homeVars := struct {
Title string
}{
Title: "Home",
}
templateLayout, err := ioutil.ReadFile("../templates/layout.html")
if err != nil {
log.Fatal(err)
}
templateHome, err := ioutil.ReadFile("../templates/home.html")
if err != nil {
log.Fatal(err)
}
t := template.New("")
t.Parse(string(templateLayout))
t.Parse(string(templateHome))
err = t.ExecuteTemplate(w, "layout", homeVars)
}
// AboutHandler /about route handler
func AboutHandler(w http.ResponseWriter, r *http.Request) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment