Skip to content

Instantly share code, notes, and snippets.

@zendrulat
Last active February 12, 2017 16:24
Show Gist options
  • Save zendrulat/b75ff18c30aea89da0ffb714e69e1066 to your computer and use it in GitHub Desktop.
Save zendrulat/b75ff18c30aea89da0ffb714e69e1066 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
"html/template"
"github.com/gorilla/mux"
)
var tpl *template.Template
func init() {
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
}
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", Index)
router.HandleFunc("/about", about)
router.HandleFunc("/links", links)
log.Fatal(http.ListenAndServe(":8080", router))
}
func Index(w http.ResponseWriter, r *http.Request) {
tpl.ExecuteTemplate(w, "index.gohtml", nil)
}
func about(w http.ResponseWriter, r *http.Request) {
tpl.ExecuteTemplate(w, "index.gohtml", nil)
}
func links(w http.ResponseWriter, r *http.Request) {
tpl.ExecuteTemplate(w, "index.gohtml", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment