Codebase list golang-github-go-kit-kit / 380dd50
transport/http: updated ServerResponseFunc to return a context to match ClientResponseFunc Geoff Berger 7 years ago
3 changed file(s) with 5 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
1414 // ServerResponseFunc may take information from a request context and use it to
1515 // manipulate a ResponseWriter. ServerResponseFuncs are only executed in
1616 // servers, after invoking the endpoint but prior to writing a response.
17 type ServerResponseFunc func(context.Context, http.ResponseWriter)
17 type ServerResponseFunc func(context.Context, http.ResponseWriter) context.Context
1818
1919 // ClientResponseFunc may take information from an HTTP request and make the
2020 // response available for consumption. ClientResponseFuncs are only executed in
2929
3030 // SetResponseHeader returns a ResponseFunc that sets the specified header.
3131 func SetResponseHeader(key, val string) ServerResponseFunc {
32 return func(_ context.Context, w http.ResponseWriter) {
32 return func(ctx context.Context, w http.ResponseWriter) context.Context {
3333 w.Header().Set(key, val)
34 return ctx
3435 }
3536 }
3637
9797 }
9898
9999 for _, f := range s.after {
100 f(ctx, w)
100 ctx = f(ctx, w)
101101 }
102102
103103 if err := s.enc(ctx, w, response); err != nil {
102102 func(context.Context, *http.Request) (interface{}, error) { return struct{}{}, nil },
103103 func(context.Context, http.ResponseWriter, interface{}) error { return nil },
104104 httptransport.ServerBefore(func(ctx context.Context, r *http.Request) context.Context { return ctx }),
105 httptransport.ServerAfter(func(ctx context.Context, w http.ResponseWriter) { return }),
105 httptransport.ServerAfter(func(ctx context.Context, w http.ResponseWriter) context.Context { return ctx }),
106106 )
107107 )
108108 go func() {