redirect.go 352 B

1234567891011121314151617181920
  1. package render
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. type Redirect struct {
  7. Code int
  8. Request *http.Request
  9. Location string
  10. }
  11. func (r Redirect) Write(w http.ResponseWriter) error {
  12. if r.Code < 300 || r.Code > 308 {
  13. panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))
  14. }
  15. http.Redirect(w, r.Request, r.Location, r.Code)
  16. return nil
  17. }