()
| 60 | } |
| 61 | |
| 62 | func ExampleResponseEncoder_EncodeError() { |
| 63 | handler := func(writer http.ResponseWriter, request *http.Request) { |
| 64 | encoder := srvhttp.NewResponseEncoder(writer) |
| 65 | encoder.EncodeError(unierr.New(codes.NotFound, "foo is missing")) |
| 66 | } |
| 67 | req := httptest.NewRequest("GET", "http://example.com/foo", nil) |
| 68 | w := httptest.NewRecorder() |
| 69 | handler(w, req) |
| 70 | |
| 71 | resp := w.Result() |
| 72 | defer resp.Body.Close() |
| 73 | body, _ := ioutil.ReadAll(resp.Body) |
| 74 | |
| 75 | fmt.Println(resp.StatusCode) |
| 76 | fmt.Println(resp.Header.Get("Content-Type")) |
| 77 | fmt.Println(string(body)) |
| 78 | |
| 79 | // Output: |
| 80 | // 404 |
| 81 | // application/json; charset=utf-8 |
| 82 | // {"code":5,"message":"foo is missing"} |
| 83 | } |
nothing calls this directly
no test coverage detected