Created
July 10, 2014 18:22
-
-
Save jakecoffman/5b7a1abbc579db2efc9e to your computer and use it in GitHub Desktop.
Simple Negroni example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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