-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathctx.go
More file actions
28 lines (21 loc) · 743 Bytes
/
ctx.go
File metadata and controls
28 lines (21 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package clickhouse
import (
"context"
"net/http"
)
type ctxKey uint8
const (
ctxTransportCallbackKey ctxKey = iota + 1
)
// TransportCallback is a transport response callback. Called before processing the http response.
type TransportCallback func(*http.Request, *http.Response) error
// CtxAddTransportCallback adds callback to work with transport response.
func CtxAddTransportCallback(ctx context.Context, f TransportCallback) context.Context {
return context.WithValue(ctx, ctxTransportCallbackKey, f)
}
func callCtxTransportCallback(ctx context.Context, req *http.Request, resp *http.Response) error {
if f, ok := ctx.Value(ctxTransportCallbackKey).(TransportCallback); ok && f != nil {
return f(req, resp)
}
return nil
}