func handler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") w.Write([]byte(`{"message": "Hello, world!"}`)) }
func handler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "max-age=3600") http.ServeFile(w, r, "example.jpg") }
func handler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Location", "http://www.example.com") w.WriteHeader(http.StatusFound) }This code sets the `Location` header to `http://www.example.com` and sends a 302 Found redirect response to the client. Package library: `net/http`