Skip to content

Instantly share code, notes, and snippets.

@jakecoffman
Created July 10, 2014 18:22
Show Gist options
  • Save jakecoffman/5b7a1abbc579db2efc9e to your computer and use it in GitHub Desktop.
Save jakecoffman/5b7a1abbc579db2efc9e to your computer and use it in GitHub Desktop.
Simple Negroni example
package main
import (
"log"
"net/http"
"github.com/codegangsta/negroni"
)
func Mids() negroni.HandlerFunc {
log.Println("Mids")
return negroni.HandlerFunc(func(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
log.Println("Before Handler")
next(rw, r)
log.Println("After Handler")
})
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
log.Println("In Handler")
w.Write([]byte("Hey yo"))
})
n := negroni.Classic()
n.Use(Mids())
n.UseHandler(mux)
n.Run(":8111")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment