Skip to content

Commit

Permalink
middleware.PageRoute (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka authored Jul 14, 2021
1 parent a63dd1f commit 69b8558
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions middleware/page_route.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package middleware

import (
"net/http"
"strings"
)

// PageRoute is a simple middleware which allows you to route a static GET request
// at the middleware stack level.
func PageRoute(path string, handler http.Handler) func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" && strings.EqualFold(r.URL.Path, path) {
handler.ServeHTTP(w, r)
return
}
h.ServeHTTP(w, r)
})
}
}

0 comments on commit 69b8558

Please sign in to comment.