forked from superfly/fly-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
27 lines (21 loc) · 870 Bytes
/
context.go
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
package fly
import "context"
type contextKey string
const (
contextKeyClient = contextKey("client")
contextKeyAuthorization = contextKey("authorization")
contextKeyRequestStart = contextKey("RequestStart")
)
// NewContextWithClient derives a Context that carries c from ctx.
func NewContextWithClient(ctx context.Context, c *Client) context.Context {
return context.WithValue(ctx, contextKeyClient, c)
}
// FromContext returns the Client ctx carries. Panics if ctx carries no Client.
func ClientFromContext(ctx context.Context) *Client {
return ctx.Value(contextKeyClient).(*Client)
}
// WithAuthorizationHeader returns a context that instructs the client to use
// the specified Authorization header value.
func WithAuthorizationHeader(ctx context.Context, hdr string) context.Context {
return context.WithValue(ctx, contextKeyAuthorization, hdr)
}