transport/http: updated ServerResponseFunc to return a context to match ClientResponseFunc
Geoff Berger
7 years ago
14 | 14 |
// ServerResponseFunc may take information from a request context and use it to
|
15 | 15 |
// manipulate a ResponseWriter. ServerResponseFuncs are only executed in
|
16 | 16 |
// 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
|
18 | 18 |
|
19 | 19 |
// ClientResponseFunc may take information from an HTTP request and make the
|
20 | 20 |
// response available for consumption. ClientResponseFuncs are only executed in
|
|
29 | 29 |
|
30 | 30 |
// SetResponseHeader returns a ResponseFunc that sets the specified header.
|
31 | 31 |
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 {
|
33 | 33 |
w.Header().Set(key, val)
|
|
34 |
return ctx
|
34 | 35 |
}
|
35 | 36 |
}
|
36 | 37 |
|
102 | 102 |
func(context.Context, *http.Request) (interface{}, error) { return struct{}{}, nil },
|
103 | 103 |
func(context.Context, http.ResponseWriter, interface{}) error { return nil },
|
104 | 104 |
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 }),
|
106 | 106 |
)
|
107 | 107 |
)
|
108 | 108 |
go func() {
|