Bind Header

  1. package main
  2. import "github.com/kataras/iris/v12"
  3. type myHeaders struct {
  4. RequestID string `header:"X-Request-Id,required"`
  5. Authentication string `header:"Authentication,required"`
  6. }
  7. func main() {
  8. app := iris.Default()
  9. r.GET("/", func(ctx iris.Context) {
  10. var hs myHeaders
  11. if err := ctx.ReadHeaders(&hs); err != nil {
  12. ctx.StopWithError(iris.StatusInternalServerError, err)
  13. return
  14. }
  15. ctx.JSON(hs)
  16. })
  17. app.Listen(":8080")
  18. }

Request

  1. curl -H "x-request-id:373713f0-6b4b-42ea-ab9f-e2e04bc38e73" -H "authentication: Bearer my-token" \
  2. http://localhost:8080

Response

  1. {
  2. "RequestID": "373713f0-6b4b-42ea-ab9f-e2e04bc38e73",
  3. "Authentication": "Bearer my-token"
  4. }