28 lines
628 B
Go
28 lines
628 B
Go
package request
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type InterceptResult = func() (string, error)
|
|
|
|
// InterceptRedirect captures a redirect url parameter
|
|
func InterceptRedirect(param string, stop bool) (func(req *http.Request, via []*http.Request) error, InterceptResult) {
|
|
var val string
|
|
return func(req *http.Request, via []*http.Request) error {
|
|
if val == "" {
|
|
if val = req.URL.Query().Get(param); val != "" && stop {
|
|
return http.ErrUseLastResponse
|
|
}
|
|
}
|
|
return nil
|
|
},
|
|
func() (string, error) {
|
|
var err error
|
|
if val == "" {
|
|
err = fmt.Errorf("%s not found", param)
|
|
}
|
|
return val, err
|
|
}
|
|
}
|