http urls monitor.

redirect.go 739B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
  2. // Use of this source code is governed by a MIT style
  3. // license that can be found in the LICENSE file.
  4. package render
  5. import (
  6. "fmt"
  7. "net/http"
  8. )
  9. type Redirect struct {
  10. Code int
  11. Request *http.Request
  12. Location string
  13. }
  14. func (r Redirect) Render(w http.ResponseWriter) error {
  15. // todo(thinkerou): go1.6 not support StatusPermanentRedirect(308)
  16. // when we upgrade go version we can use http.StatusPermanentRedirect
  17. if (r.Code < 300 || r.Code > 308) && r.Code != 201 {
  18. panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))
  19. }
  20. http.Redirect(w, r.Request, r.Location, r.Code)
  21. return nil
  22. }
  23. func (r Redirect) WriteContentType(http.ResponseWriter) {}