httpx: Add new redirect
This commit is contained in:
parent
41d41035e3
commit
8e2d2cce3e
5 changed files with 123 additions and 35 deletions
22
pkg/httpx/redirect.go
Normal file
22
pkg/httpx/redirect.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package httpx
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// RedirectHandler represents a handler that redirects the user to the address returned
|
||||
type RedirectHandler func(r *http.Request) (string, int, error)
|
||||
|
||||
// ServeHTTP calls r(r) and returns json
|
||||
func (rh RedirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// call the function
|
||||
url, code, err := rh(r)
|
||||
|
||||
// intercept the errors
|
||||
if textInterceptor.Intercept(w, r, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// do the redirect
|
||||
http.Redirect(w, r, url, code)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue