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