SetHeader

设置HTTP响应头的值,如果该值已存在,则覆盖。

Example

  1. package main
  2. import (
  3. "math/rand"
  4. "strconv"
  5. "github.com/vicanso/elton"
  6. "github.com/vicanso/elton/middleware"
  7. )
  8. func main() {
  9. e := elton.New()
  10. e.Use(middleware.NewDefaultResponder())
  11. e.GET("/", func(c *elton.Context) (err error) {
  12. c.SetHeader("X-Response-Id", strconv.Itoa(rand.Int()))
  13. c.Body = c.GetHeader("X-Response-Id")
  14. return
  15. })
  16. err := e.ListenAndServe(":3000")
  17. if err != nil {
  18. panic(err)
  19. }
  20. }