forked from pivotal-cf/brokerapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
42 lines (34 loc) · 957 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package utils
import (
"context"
"github.com/pivotal-cf/brokerapi/domain"
)
type contextKey string
const (
contextKeyService contextKey = "brokerapi_service"
contextKeyPlan contextKey = "brokerapi_plan"
)
func AddServiceToContext(ctx context.Context, service *domain.Service) context.Context {
if service != nil {
return context.WithValue(ctx, contextKeyService, service)
}
return ctx
}
func RetrieveServiceFromContext(ctx context.Context) *domain.Service {
if value := ctx.Value(contextKeyService); value != nil {
return value.(*domain.Service)
}
return nil
}
func AddServicePlanToContext(ctx context.Context, plan *domain.ServicePlan) context.Context {
if plan != nil {
return context.WithValue(ctx, contextKeyPlan, plan)
}
return ctx
}
func RetrieveServicePlanFromContext(ctx context.Context) *domain.ServicePlan {
if value := ctx.Value(contextKeyPlan); value != nil {
return value.(*domain.ServicePlan)
}
return nil
}