init
This commit is contained in:
commit
fa6a4c650f
93 files changed
+6555
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func NormalizePath(
|
||||
next http.Handler,
|
||||
) http.Handler {
|
||||
|
||||
return http.HandlerFunc(
|
||||
func(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
) {
|
||||
|
||||
p := r.URL.Path
|
||||
|
||||
if p != "/" {
|
||||
|
||||
for strings.HasSuffix(
|
||||
p,
|
||||
"/",
|
||||
) {
|
||||
|
||||
p = strings.TrimSuffix(
|
||||
p,
|
||||
"/",
|
||||
)
|
||||
}
|
||||
|
||||
if p == "" {
|
||||
p = "/"
|
||||
}
|
||||
|
||||
if p != r.URL.Path {
|
||||
|
||||
http.Redirect(
|
||||
w,
|
||||
r,
|
||||
p,
|
||||
http.StatusMovedPermanently,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user