-
Notifications
You must be signed in to change notification settings - Fork 5
/
context.go
33 lines (25 loc) · 852 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
package iopipe
import (
"context"
"github.com/aws/aws-lambda-go/lambdacontext"
)
// ContextWrapper wraps the AWS lambda context
type ContextWrapper struct {
*lambdacontext.LambdaContext
IOpipe *HandlerWrapper
}
type key struct{}
var contextKey = &key{}
// NewContext returns a new Context that contains the IOpipe context wrapper
func NewContext(parent context.Context, cw *ContextWrapper) context.Context {
return context.WithValue(parent, contextKey, cw)
}
// FromContext returns the context wrapper stored in ctx
func FromContext(ctx context.Context) (*ContextWrapper, bool) {
cw, ok := ctx.Value(contextKey).(*ContextWrapper)
return cw, ok
}
// NewContextWrapper returns a new context wrapper
func NewContextWrapper(ctx *lambdacontext.LambdaContext, handler *HandlerWrapper) *ContextWrapper {
return &ContextWrapper{ctx, handler}
}