1
0
Fork 0

Add Rule AddPrefix

This commit is contained in:
Julien Salleyron 2016-12-02 13:40:18 +01:00
parent 318ff52ff3
commit d9fc66fdbc
3 changed files with 43 additions and 4 deletions

22
middlewares/addPrefix.go Normal file
View file

@ -0,0 +1,22 @@
package middlewares
import (
"net/http"
)
// AddPrefix is a middleware used to add prefix to an URL request
type AddPrefix struct {
Handler http.Handler
Prefix string
}
func (s *AddPrefix) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.URL.Path = s.Prefix + r.URL.Path
r.RequestURI = r.URL.RequestURI()
s.Handler.ServeHTTP(w, r)
}
// SetHandler sets handler
func (s *AddPrefix) SetHandler(Handler http.Handler) {
s.Handler = Handler
}