-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
70 lines (56 loc) · 2.15 KB
/
Copy pathcontext.go
File metadata and controls
70 lines (56 loc) · 2.15 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package voker
import (
"context"
)
// ClientApplication contains metadata about the client application
type ClientApplication struct {
InstallationID string `json:"installation_id"`
AppTitle string `json:"app_title"`
AppVersionCode string `json:"app_version_code"`
AppPackageName string `json:"app_package_name"`
}
// ClientContext contains information about the client application and device
type ClientContext struct {
Client ClientApplication `json:"client"`
Env map[string]string `json:"env"`
Custom map[string]string `json:"custom"`
}
// CognitoIdentity contains Cognito identity information.
//
// The JSON tags match the camelCase payload Lambda delivers in the
// Lambda-Runtime-Cognito-Identity header, for example:
//
// {"cognitoIdentityId":"...","cognitoIdentityPoolId":"..."}
type CognitoIdentity struct {
CognitoIdentityID string `json:"cognitoIdentityId"`
CognitoIdentityPoolID string `json:"cognitoIdentityPoolId"`
}
// LambdaContext contains the metadata for a Lambda invocation
type LambdaContext struct {
// AwsRequestID is the unique request identifier
AwsRequestID string
// InvokedFunctionArn is the ARN of the Lambda function being invoked
InvokedFunctionArn string
// TraceID is the invocation-scoped AWS X-Ray trace header received from the
// Lambda Runtime API.
TraceID string
// TenantID is the tenant identifier for functions using Lambda tenant
// isolation mode. It is empty when the function does not use tenant
// isolation or the invocation carries no tenant ID.
TenantID string
// Identity contains Cognito identity information
Identity CognitoIdentity
// ClientContext contains client application information
ClientContext ClientContext
}
type contextKey struct{}
var lambdaContextKey = &contextKey{}
// NewContext returns a new context with the LambdaContext attached
func NewContext(parent context.Context, lc *LambdaContext) context.Context {
return context.WithValue(parent, lambdaContextKey, lc)
}
// FromContext extracts the LambdaContext from the context, if present
func FromContext(ctx context.Context) (*LambdaContext, bool) {
lc, ok := ctx.Value(lambdaContextKey).(*LambdaContext)
return lc, ok
}