// +build ignore,OMIT | |
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"net/http/httptest" | |
) | |
func main() { | |
// START OMIT | |
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintln(w, "Hello, client") | |
})) | |
defer ts.Close() | |
res, err := http.Get(ts.URL) | |
if err != nil { | |
log.Fatal(err) | |
} | |
greeting, err := ioutil.ReadAll(res.Body) | |
res.Body.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("%s", greeting) | |
// STOP OMIT | |
} |