I know that I can add headers to each HTTP request manually using
cli := &http.Client{}
req, err := http.NewRequest("GET", "https://myhost", nil)
req.Header.Add("X-Test", "true")
if err != nil {
panic(err)
}
rsp, err := cli.Do(req)
but I want to add this header automatically for each HTTP request in my app.
What is the best way to do it?
client.Do
with custom function to append headers, butclient.Get
andclient.Post
looks more laconic thanclient.NewRequest
, error checking, thenmyDo
func. – Morbific