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.Dowith custom function to append headers, butclient.Getandclient.Postlooks more laconic thanclient.NewRequest, error checking, thenmyDofunc. - Kirill