Added context to apig router config and apig context

This commit is contained in:
mitchelljfs 2018-08-03 00:01:13 -07:00
parent da00efd4a3
commit 639d28c78e
3 changed files with 10 additions and 1 deletions

2
Gopkg.lock generated
View File

@ -48,6 +48,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "751d4fc4b7be23b18796aed082f5e83d9ba309c184255d4c63d8225cc0048152"
inputs-digest = "5da761903d61cf9e47d309477db924d6e310f97fbd7c553ff46af570b65d4356"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -33,6 +33,10 @@
name = "github.com/aws/aws-lambda-go"
version = "1.2.0"
[[constraint]]
name = "github.com/smartystreets/goconvey"
version = "1.6.3"
[prune]
go-tests = true
unused-packages = true

View File

@ -1,6 +1,7 @@
package lambdarouter
import (
"context"
"encoding/json"
"log"
"net/http"
@ -24,6 +25,7 @@ const (
// Fill the Status and Body, or Status and Error to respond.
type APIGContext struct {
Claims map[string]interface{}
Context context.Context
Path map[string]string
QryStr map[string]string
Request *events.APIGatewayProxyRequest
@ -43,12 +45,14 @@ type APIGRouter struct {
params map[string]string
prefix string
headers map[string]string
context context.Context
}
// APIGRouterConfig is used as the input to NewAPIGRouter, request is your incoming
// apig request and prefix will be stripped of all incoming request paths. Headers
// will be sent with all responses.
type APIGRouterConfig struct {
Context context.Context
Request *events.APIGatewayProxyRequest
Prefix string
Headers map[string]string
@ -144,6 +148,7 @@ func (r *APIGRouter) Respond() events.APIGatewayProxyResponse {
Path: r.request.PathParameters,
QryStr: r.request.QueryStringParameters,
Request: r.request,
Context: r.context,
}
if r.request.RequestContext.Authorizer["claims"] != nil {
ctx.Claims = r.request.RequestContext.Authorizer["claims"].(map[string]interface{})