You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

page_route.go 519B

1234567891011121314151617181920
  1. package middleware
  2. import (
  3. "net/http"
  4. "strings"
  5. )
  6. // PageRoute is a simple middleware which allows you to route a static GET request
  7. // at the middleware stack level.
  8. func PageRoute(path string, handler http.Handler) func(http.Handler) http.Handler {
  9. return func(next http.Handler) http.Handler {
  10. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  11. if r.Method == "GET" && strings.EqualFold(r.URL.Path, path) {
  12. handler.ServeHTTP(w, r)
  13. return
  14. }
  15. next.ServeHTTP(w, r)
  16. })
  17. }
  18. }