Redirect

重定向当前请求。

Example

  1. package main
  2. import (
  3. "github.com/vicanso/elton"
  4. "github.com/vicanso/elton/middleware"
  5. )
  6. func main() {
  7. e := elton.New()
  8. e.Use(middleware.NewDefaultResponder())
  9. e.GET("/", func(c *elton.Context) (err error) {
  10. c.Body = "Hello, World!"
  11. return
  12. })
  13. e.GET("/redirect", func(c *elton.Context) (err error) {
  14. err = c.Redirect(301, "/")
  15. return
  16. })
  17. err := e.ListenAndServe(":3000")
  18. if err != nil {
  19. panic(err)
  20. }
  21. }