req, err := http.NewRequest("POST", "http://example.com/api", bytes.NewBuffer(reqBody)) if err != nil { // handle error } req.Header.Set("Content-Type", "application/json")
w.Header().Set("Content-Type", "text/html") w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")In both examples, we are using the `Set()` method of the `Header` type to set the value of one or more headers. In the first example, we set the `Content-Type` header for an HTTP request using a `POST` method. In the second example, we set multiple headers for an HTTP response. The `Header` type is a part of the `net/http` package which is a standard library in Go.