()
| 20 | ) |
| 21 | |
| 22 | func ExampleNewServer() { |
| 23 | tb := &tomb.Tomb{} |
| 24 | sl := FuncServlet("/hello/{name}", func(w http.ResponseWriter, r *http.Request) { |
| 25 | name := mux.Vars(r)["name"] |
| 26 | fmt.Fprintf(w, "hello %s", name) |
| 27 | }) |
| 28 | |
| 29 | sl = UseServlet(sl, |
| 30 | // Should be first to properly add tags and logging fields to the context |
| 31 | RequestContextMiddleware, |
| 32 | NewRequestMetricsMiddleware(&RequestMetricsMiddlewareConfig{BodyLogPredicate: LogErrorBody}), |
| 33 | safely.Middleware, |
| 34 | ) |
| 35 | |
| 36 | s := NewServer(tb, "127.0.0.1:0", sl) |
| 37 | defer s.Tomb().Kill(nil) |
| 38 | safely.Run(s) |
| 39 | |
| 40 | u := httpScheme + s.Addr().String() + "/hello/world" |
| 41 | |
| 42 | res, _ := http.Get(u) |
| 43 | io.Copy(os.Stdout, res.Body) |
| 44 | |
| 45 | // Output: |
| 46 | // hello world |
| 47 | } |
| 48 | |
| 49 | func TestNewServer(t *testing.T) { |
| 50 | logOutput := &syncio.Buffer{} |
nothing calls this directly
no test coverage detected