// Register the route...
app.Get("/", handler)
func handler(ctx iris.Context) {
requestID := ctx.GetHeader("X-Request-Id")
authentication := ctx.GetHeader("Authentication")
}
Let's create our Go structure.
type myHeaders struct {
RequestID string `header:"X-Request-Id,required"`
Authentication string `header:"Authentication,required"`
}
Now, the handler which reads the request headers and binds them to a "myHeaders" value.
func handler(ctx iris.Context) {
var hs myHeaders
if err := ctx.ReadHeaders(&hs); err != nil {
ctx.StopWithError(iris.StatusInternalServerError, err)
return
}
ctx.JSON(hs)
}
curl -H "x-request-id:373713f0-6b4b-42ea-ab9f-e2e04bc38e73" -H "authentication: Bearer my-token" \
http://localhost:8080
{
"RequestID": "373713f0-6b4b-42ea-ab9f-e2e04bc38e73",
"Authentication": "Bearer my-token"
}