resp, err := http.Get("https://example.com") if err != nil { log.Fatal(err) } fmt.Println("HTTP protocol version:", resp.ProtoMajor)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Hello, World!") })In this example, we define an HTTP handler function using the `http.HandleFunc` function from the `net/http` package. Within the handler function, we set the response header to `text/plain` using the `w.Header().Set` method and write an HTTP status code of `200 OK` to the response using the `w.WriteHeader` method. Finally, we use the `fmt.Fprintf` function to write the "Hello, World!" message to the response body. Although this example does not explicitly use the `ProtoMajor` field of the `http.Response` struct, its usage is implied as part of the HTTP communication between the client and server. Package library: `net/http`