1
// Copyright 2013 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
15
func ExampleResponseRecorder() {
16
handler := func(w http.ResponseWriter, r *http.Request) {
17
http.Error(w, "something failed", http.StatusInternalServerError)
20
req, err := http.NewRequest("GET", "http://example.com/foo", nil)
25
w := httptest.NewRecorder()
28
fmt.Printf("%d - %s", w.Code, w.Body.String())
29
// Output: 500 - something failed
32
func ExampleServer() {
33
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
34
fmt.Fprintln(w, "Hello, client")
38
res, err := http.Get(ts.URL)
42
greeting, err := ioutil.ReadAll(res.Body)
48
fmt.Printf("%s", greeting)
49
// Output: Hello, client