10 func ExamplePopulateRequestContext() {
12 func(ctx context.Context, request interface{}) (response interface{}, err error) {
13 fmt.Println("Method", ctx.Value(ContextKeyRequestMethod).(string))
14 fmt.Println("RequestPath", ctx.Value(ContextKeyRequestPath).(string))
15 fmt.Println("RequestURI", ctx.Value(ContextKeyRequestURI).(string))
16 fmt.Println("X-Request-ID", ctx.Value(ContextKeyRequestXRequestID).(string))
17 return struct{}{}, nil
19 func(context.Context, *http.Request) (interface{}, error) { return struct{}{}, nil },
20 func(context.Context, http.ResponseWriter, interface{}) error { return nil },
21 ServerBefore(PopulateRequestContext),
24 server := httptest.NewServer(handler)
27 req, _ := http.NewRequest("PATCH", fmt.Sprintf("%s/search?q=sympatico", server.URL), nil)
28 req.Header.Set("X-Request-Id", "a1b2c3d4e5")
29 http.DefaultClient.Do(req)
33 // RequestPath /search
34 // RequestURI /search?q=sympatico
35 // X-Request-ID a1b2c3d4e5