package main import ( "net/http" "fmt" ) func main() { req, _ := http.NewRequest("GET", "https://api.github.com/users/octocat", nil) req.Header.Set("Accept", "application/vnd.github+json") resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() fmt.Println(resp.StatusCode) }
package main import ( "net/http" "fmt" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") fmt.Fprint(w, "In this example, we create a basic HTTP server that responds with HTML content. The response header is set to specify that the content type is HTML. Package library: net/httpHello, world!
") }) http.ListenAndServe(":8080", nil) }