Add Rule AddPrefix
This commit is contained in:
parent
318ff52ff3
commit
d9fc66fdbc
3 changed files with 43 additions and 4 deletions
22
middlewares/addPrefix.go
Normal file
22
middlewares/addPrefix.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue