req, err := http.NewRequest("GET", "http://example.com", nil) if err != nil { // handle error } req.Header.Add("X-Auth-Token", "someAuthToken")
header := http.Header{} header.Add("Content-Type", "application/json") header.Add("Authorization", "Bearer "+accessToken) req, err := http.NewRequest("POST", "http://example.com/api/resource", nil) if err != nil { // handle error } req.Header = headerIn this example, we create a new header and add two key-value pairs to it. Then we assign the header to the request using `req.Header = header`. The package library used in these examples is `net/http`.