Skip to content

Instantly share code, notes, and snippets.

@maxmcd
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxmcd/05774dc7cdea37248baa to your computer and use it in GitHub Desktop.
Save maxmcd/05774dc7cdea37248baa to your computer and use it in GitHub Desktop.
gitbao
package main
import (
"fmt"
"log"
"net/http"
"os"
"text/template"
_ "github.com/gitbao/gitbao"
"github.com/gorilla/mux"
)
var T *template.Template
var goPath string
func init() {
goPath = os.Getenv("GOPATH")
T = template.Must(template.ParseGlob(goPath + "/src/github.com/gitbao/gitbao/cmd/kitchen/templates/*"))
}
func main() {
r := mux.NewRouter()
r.StrictSlash(true)
r.HandleFunc("/", IndexHandler).Methods("GET")
http.Handle("/", Middleware(r))
fmt.Println("Broadcasting Kitchen on port 8000")
r.PathPrefix("/").Handler(http.FileServer(http.Dir(goPath + "src/github.com/gitbao/gitbao/cmd/kitchen/public/")))
http.ListenAndServe(":8000", nil)
}
func Middleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println(r.Host, r.URL)
h.ServeHTTP(w, r)
})
}
func RenderTemplate(w http.ResponseWriter, tmpl string, data interface{}) {
T.ExecuteTemplate(w, tmpl+".html", data)
}
func IndexHandler(w http.ResponseWriter, req *http.Request) {
RenderTemplate(w, "index", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment