-
-
Save piotrkubisa/03e04aaa8a4c5992189c556596f12689 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"resource": "/{proxy+}", | |
"path": "/hello/world", | |
"httpMethod": "POST", | |
"headers": { | |
"Accept": "*/*", | |
"Accept-Encoding": "gzip, deflate", | |
"cache-control": "no-cache", | |
"CloudFront-Forwarded-Proto": "https", | |
"CloudFront-Is-Desktop-Viewer": "true", | |
"CloudFront-Is-Mobile-Viewer": "false", | |
"CloudFront-Is-SmartTV-Viewer": "false", | |
"CloudFront-Is-Tablet-Viewer": "false", | |
"CloudFront-Viewer-Country": "US", | |
"Content-Type": "application/json", | |
"headerName": "headerValue", | |
"Host": "gy415nuibc.execute-api.us-east-1.amazonaws.com", | |
"Postman-Token": "9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f", | |
"User-Agent": "PostmanRuntime/2.4.5", | |
"Via": "1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)", | |
"X-Amz-Cf-Id": "pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==", | |
"X-Forwarded-For": "54.240.196.186, 54.182.214.83", | |
"X-Forwarded-Port": "443", | |
"X-Forwarded-Proto": "https" | |
}, | |
"multiValueHeaders": { | |
"Accept": [ | |
"*/*" | |
], | |
"Accept-Encoding": [ | |
"gzip, deflate" | |
], | |
"cache-control": [ | |
"no-cache" | |
], | |
"CloudFront-Forwarded-Proto": [ | |
"https" | |
], | |
"CloudFront-Is-Desktop-Viewer": [ | |
"true" | |
], | |
"CloudFront-Is-Mobile-Viewer": [ | |
"false" | |
], | |
"CloudFront-Is-SmartTV-Viewer": [ | |
"false" | |
], | |
"CloudFront-Is-Tablet-Viewer": [ | |
"false" | |
], | |
"CloudFront-Viewer-Country": [ | |
"US" | |
], | |
"Content-Type": [ | |
"application/json" | |
], | |
"headerName": [ | |
"headerValue" | |
], | |
"Host": [ | |
"gy415nuibc.execute-api.us-east-1.amazonaws.com" | |
], | |
"Postman-Token": [ | |
"9f583ef0-ed83-4a38-aef3-eb9ce3f7a57f" | |
], | |
"User-Agent": [ | |
"PostmanRuntime/2.4.5" | |
], | |
"Via": [ | |
"1.1 d98420743a69852491bbdea73f7680bd.cloudfront.net (CloudFront)" | |
], | |
"X-Amz-Cf-Id": [ | |
"pn-PWIJc6thYnZm5P0NMgOUglL1DYtl0gdeJky8tqsg8iS_sgsKD1A==" | |
], | |
"X-Forwarded-For": [ | |
"54.240.196.186, 54.182.214.83" | |
], | |
"X-Forwarded-Port": [ | |
"443" | |
], | |
"X-Forwarded-Proto": [ | |
"https" | |
] | |
}, | |
"queryStringParameters": { | |
"name": "me" | |
}, | |
"multiValueQueryStringParameters": { | |
"name": [ | |
"me" | |
] | |
}, | |
"pathParameters": { | |
"proxy": "hello/world" | |
}, | |
"stageVariables": { | |
"stageVariableName": "stageVariableValue" | |
}, | |
"requestContext": { | |
"accountId": "12345678912", | |
"resourceId": "roq9wj", | |
"stage": "testStage", | |
"requestId": "deef4878-7910-11e6-8f14-25afc3e9ae33", | |
"identity": { | |
"cognitoIdentityPoolId": "theCognitoIdentityPoolId", | |
"accountId": "theAccountId", | |
"cognitoIdentityId": "theCognitoIdentityId", | |
"caller": "theCaller", | |
"apiKey": "theApiKey", | |
"accessKey": "ANEXAMPLEOFACCESSKEY", | |
"sourceIp": "192.168.196.186", | |
"cognitoAuthenticationType": "theCognitoAuthenticationType", | |
"cognitoAuthenticationProvider": "theCognitoAuthenticationProvider", | |
"userArn": "theUserArn", | |
"userAgent": "PostmanRuntime/2.4.5", | |
"user": "theUser" | |
}, | |
"authorizer": { | |
"principalId": "admin", | |
"clientId": 1, | |
"clientName": "Exata" | |
}, | |
"resourcePath": "/{proxy+}", | |
"httpMethod": "POST", | |
"apiId": "gy415nuibc" | |
}, | |
"body": "{\r\n\t\"a\": 1\r\n}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package apigo_test | |
import ( | |
"context" | |
"encoding/json" | |
"io/ioutil" | |
"net/http" | |
"testing" | |
"github.com/apex/gateway" | |
"github.com/aws/aws-lambda-go/events" | |
"github.com/awslabs/aws-lambda-go-api-proxy/handlerfunc" | |
"github.com/piotrkubisa/apigo" | |
) | |
func BenchmarkGateway_Serve(b *testing.B) { | |
g := apigo.NewGateway("api.example.com", http.HandlerFunc(helloHandler)) | |
payload, err := ioutil.ReadFile("./vendor/github.com/aws/aws-lambda-go/events/testdata/apigw-request.json") | |
if err != nil { | |
panic(err) | |
} | |
var ev events.APIGatewayProxyRequest | |
if err := json.Unmarshal(payload, &ev); err != nil { | |
panic(err) | |
} | |
for i := 0; i < b.N; i++ { | |
g.Serve(context.TODO(), ev) | |
} | |
} | |
func helloHandler(w http.ResponseWriter, r *http.Request) { | |
w.Header().Set("Content-Type", "application/json") | |
w.WriteHeader(http.StatusTeapot) | |
w.Write([]byte(`"Hello World"`)) | |
} | |
func BenchmarkApexFunc(b *testing.B) { | |
h := http.HandlerFunc(helloHandler) | |
gServe := func(ctx context.Context, e events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { | |
r, err := gateway.NewRequest(ctx, e) | |
if err != nil { | |
return events.APIGatewayProxyResponse{}, err | |
} | |
w := gateway.NewResponse() | |
h.ServeHTTP(w, r) | |
return w.End(), nil | |
} | |
payload, err := ioutil.ReadFile("./vendor/github.com/aws/aws-lambda-go/events/testdata/apigw-request.json") | |
if err != nil { | |
panic(err) | |
} | |
var ev events.APIGatewayProxyRequest | |
if err := json.Unmarshal(payload, &ev); err != nil { | |
panic(err) | |
} | |
for i := 0; i < b.N; i++ { | |
gServe(context.TODO(), ev) | |
} | |
} | |
func BenchmarkLambdaProxy(b *testing.B) { | |
g := handlerfunc.New(helloHandler) | |
payload, err := ioutil.ReadFile("./vendor/github.com/aws/aws-lambda-go/events/testdata/apigw-request.json") | |
if err != nil { | |
panic(err) | |
} | |
var ev events.APIGatewayProxyRequest | |
if err := json.Unmarshal(payload, &ev); err != nil { | |
panic(err) | |
} | |
for i := 0; i < b.N; i++ { | |
g.Proxy(ev) | |
} | |
} |
Author
piotrkubisa
commented
Jun 20, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment