more index work

This commit is contained in:
Mark McGranaghan
2012-09-23 14:38:39 -07:00
parent 3474d39dc5
commit c19a29193e
112 changed files with 8 additions and 39 deletions

View File

@@ -0,0 +1,25 @@
// ## HTTP Server Middleware
package main
import "net/http"
import "fmt"
func hello(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/plain")
fmt.Fprintln(res, "Hello wrapped world")
}
func wrapMiddleware(f http.HandlerFunc) http.HandlerFunc {
return func(res http.ResponseWriter, req *http.Request) {
fmt.Println("before")
f(res, req)
fmt.Println("after")
}
}
func main() {
handler := wrapMiddleware(hello)
http.HandleFunc("/", handler)
http.ListenAndServe(":5000", nil)
}