()
| 33 | } |
| 34 | |
| 35 | func ExampleResponseEncoder_EncodeResponse() { |
| 36 | handler := func(writer http.ResponseWriter, request *http.Request) { |
| 37 | encoder := srvhttp.NewResponseEncoder(writer) |
| 38 | encoder.EncodeResponse(struct { |
| 39 | Foo string `json:"foo"` |
| 40 | }{ |
| 41 | Foo: "bar", |
| 42 | }) |
| 43 | } |
| 44 | req := httptest.NewRequest("GET", "http://example.com/foo", nil) |
| 45 | w := httptest.NewRecorder() |
| 46 | handler(w, req) |
| 47 | |
| 48 | resp := w.Result() |
| 49 | defer resp.Body.Close() |
| 50 | body, _ := ioutil.ReadAll(resp.Body) |
| 51 | |
| 52 | fmt.Println(resp.StatusCode) |
| 53 | fmt.Println(resp.Header.Get("Content-Type")) |
| 54 | fmt.Println(string(body)) |
| 55 | |
| 56 | // Output: |
| 57 | // 200 |
| 58 | // application/json; charset=utf-8 |
| 59 | // {"foo":"bar"} |
| 60 | } |
| 61 | |
| 62 | func ExampleResponseEncoder_EncodeError() { |
| 63 | handler := func(writer http.ResponseWriter, request *http.Request) { |
nothing calls this directly
no test coverage detected