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.

path_rewrite.go 422B

12345678910111213141516
  1. package middleware
  2. import (
  3. "net/http"
  4. "strings"
  5. )
  6. // PathRewrite is a simple middleware which allows you to rewrite the request URL path.
  7. func PathRewrite(old, new string) func(http.Handler) http.Handler {
  8. return func(next http.Handler) http.Handler {
  9. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  10. r.URL.Path = strings.Replace(r.URL.Path, old, new, 1)
  11. next.ServeHTTP(w, r)
  12. })
  13. }
  14. }