fix context usage across codebase
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -8,12 +8,18 @@ type transportKey struct{}
|
||||
|
||||
// FromContext get transport from context
|
||||
func FromContext(ctx context.Context) (Transport, bool) {
|
||||
if ctx == nil {
|
||||
return nil, false
|
||||
}
|
||||
c, ok := ctx.Value(transportKey{}).(Transport)
|
||||
return c, ok
|
||||
}
|
||||
|
||||
// NewContext put transport in context
|
||||
func NewContext(ctx context.Context, c Transport) context.Context {
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
return context.WithValue(ctx, transportKey{}, c)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user