How can one define the headers once for all endpoints? #658
-
Currently I'm defining headers like this:
With this I have to add the response header struct to every output struct that I define. I would like to set the headers just once where I define the routes. Otherwise I have to do it like this for each route:
Is that possible? I also have a small side-issue with this in that it returns "responseheaders" as a header in addition to cache-control: Appreciate any help that I can get on this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@artisanphil this might be a good case for a middleware. You can document it as part of the top-level API description saying it's a common header or loop through and add it to all the operations as needed. Example: https://go.dev/play/p/ezWCcctZRg9 For the other issue, I believe #656 fixes is and will get released ASAP. |
Beta Was this translation helpful? Give feedback.
@danielgtaylor Thank you.
I got it working like this:
For the documentation itself, I'm now just describing the headers on the overview page rather than per endpoint (e.g. under
config.Info.Description
).