blob: 5e80e2551b72d08ad3d1037494b1f7b78bd23352 [file] [log] [blame]
// +build ignore,OMIT
package main
import (
"fmt"
"net/http"
)
func authRequired(f http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.FormValue("user") == "" {
http.Error(w, "unknown user", http.StatusForbidden)
return
}
f(w, r)
}
}
var hiHandler = authRequired(
func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi, %v", r.FormValue("user"))
},
)
func main() {
http.HandleFunc("/hi", hiHandler)
http.ListenAndServe(":8080", nil)
}