-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
33 lines (26 loc) · 901 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 goscf
import (
"context"
"github.com/tencentyun/scf-go-lib/events"
)
func RequestFromContext(ctx context.Context) *events.APIGatewayRequest {
return ctx.Value("request").(*events.APIGatewayRequest)
}
func ContextWithRequest(ctx context.Context, request *events.APIGatewayRequest) context.Context {
return context.WithValue(ctx, "request", request)
}
func ResponseFromContext(ctx context.Context) *events.APIGatewayResponse {
return ctx.Value("response").(*events.APIGatewayResponse)
}
func ContextWithResponse(ctx context.Context, response *events.APIGatewayResponse) context.Context {
return context.WithValue(ctx, "response", response)
}
func IpFromContext(ctx context.Context) string {
if ctx.Value("ip") != nil {
return ctx.Value("ip").(string)
}
return ""
}
func ContextWithIp(ctx context.Context, ip string) context.Context {
return context.WithValue(ctx, "ip", ip)
}