func getHeader(c *gin.Context) { value := c.Request.Header.Get("Authorization") c.String(http.StatusOK, "The value of Authorization header is %s", value) }
func setHeader(c *gin.Context) { c.Header("X-Custom-Header", "hello world") c.String(http.StatusOK, "Header set successfully") }In both examples, we use the gin.Context object to access the request headers. In the first example, we retrieve the value of the "Authorization" header using the Get() function. In the second example, we set a custom header using the Header() function. Overall, the gin.Context.Header package is an essential library in the Gin framework for handling HTTP request headers.