wisski-cloud-distillery/pkg/httpx/redirect.go
2022-11-24 14:19:17 +01:00

22 lines
494 B
Go

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)
}