forked from akrylysov/algnhsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
42 lines (34 loc) · 1.19 KB
/
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 algnhsa
import (
"context"
"github.com/aws/aws-lambda-go/events"
)
type contextKey int
const (
proxyRequestContextKey contextKey = iota
albRequestContextKey
)
func newProxyRequestContext(ctx context.Context, event events.APIGatewayProxyRequest) context.Context {
return context.WithValue(ctx, proxyRequestContextKey, event)
}
// ProxyRequestFromContext extracts the APIGatewayProxyRequest event from ctx.
func ProxyRequestFromContext(ctx context.Context) (events.APIGatewayProxyRequest, bool) {
val := ctx.Value(proxyRequestContextKey)
if val == nil {
return events.APIGatewayProxyRequest{}, false
}
event, ok := val.(events.APIGatewayProxyRequest)
return event, ok
}
func newTargetGroupRequestContext(ctx context.Context, event events.ALBTargetGroupRequest) context.Context {
return context.WithValue(ctx, albRequestContextKey, event)
}
// TargetGroupRequestFromContext extracts the ALBTargetGroupRequest event from ctx.
func TargetGroupRequestFromContext(ctx context.Context) (events.ALBTargetGroupRequest, bool) {
val := ctx.Value(albRequestContextKey)
if val == nil {
return events.ALBTargetGroupRequest{}, false
}
event, ok := val.(events.ALBTargetGroupRequest)
return event, ok
}