Reputation: 811
How to add default header to response returned in Gin golang? I wanted to add Cache-Control: public, max-age=604800, immutable
to the every response that I return.
Upvotes: 3
Views: 8360
Reputation: 811
I have solved the above question with following code
r := gin.New()
r.Use(func(c *gin.Context) {
c.Writer.Header().Set("Cache-Control", "public, max-age=604800, immutable")
})
However, it is not really good idea to add the given header to every request. It is better to add the header to cdn or static items. It can be achieved with NGINX or Traefik.
Upvotes: 6