package web import ( "log" "net" "net/http" "github.com/Jaculabilis/intake/core" ) type Env struct { db *core.DB } func logged(handler http.HandlerFunc) http.HandlerFunc { return func(writer http.ResponseWriter, req *http.Request) { log.Printf("%s %s", req.Method, req.URL.Path) handler(writer, req) } } func handleFunc(pattern string, handler http.HandlerFunc) { http.HandleFunc(pattern, logged(handler)) } func RunServer(db *core.DB, addr string, port string) { env := &Env{db} bind := net.JoinHostPort(addr, port) handleFunc("/", env.rootHandler) handleFunc("/style.css", env.styleHandler) log.Fatal(http.ListenAndServe(bind, nil)) }