I am trying to write a Go http handler which is performance sensitive (in particular I want to minimize the amount of RAM used). The handler sets a bunch of headers for each request. All headers are always the same and with the same values.
Is there a way to use a single const
for all headers and set them all in a single call?
Example. Instead of doing this for all requests:
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Cache-Control", "no-cache")
w.Header().Set("Connection", "keep-alive")
…do something like this:
const staticHeaders = `
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Connection: keep-alive`
w.Headers.WriteRaw(staticHeaders)
Is that possible?