package main import ( "fmt" "net/http" "goji.io" "goji.io/pat" "golang.org/x/net/context" ) func hello(ctx context.Context, w http.ResponseWriter, r *http.Request) { name := pat.Param(ctx, "name") fmt.Fprintf(w, "Hello, %s!", name) } var routes = []string{ "/", "/hello", "/hello/:name", } // Middleware returns a http.Handler that does the actual permission setting. func middleware(h goji.Handler) goji.Handler { fn := func(ctx context.Context, w http.ResponseWriter, r *http.Request) { for _, resource := range routes { p := pat.New(resource) if p.Match(ctx, r) != nil { fmt.Println("match!") break } else { fmt.Println("no match..") } } h.ServeHTTPC(ctx, w, r) } return goji.HandlerFunc(fn) } func main() { mux := goji.NewMux() mux.HandleFuncC(pat.Get("/hello/:name"), hello) mux.UseC(middleware) http.ListenAndServe("localhost:8000", mux) }