awslabs / aws-lambda-go-api-proxy

lambda-go-api-proxy makes it easy to port APIs written with Go frameworks such as Gin (https://gin-gonic.github.io/gin/ ) to AWS Lambda and Amazon API Gateway.
Apache License 2.0
1.03k stars 198 forks source link

Automatic/passive switching between V1 and V2 API Gateway API requests and responses based on JSON marshal/unmarshal interfaces for Gorillia, & Cookies fixed for v2 & Tests fixed for V2 (wrong structure) #109

Closed aubelsb2 closed 2 years ago

aubelsb2 commented 2 years ago

This is an attempt at producing an interface that automatically switches between V1 and V2 API strctures based on the presense of keys in the request object, for gorillia mux.

It adds 2 new structures:

Which implement:

type Unmarshaler interface {
    UnmarshalJSON([]byte) error
}

and

type Marshaler interface {
    MarshalJSON() ([]byte, error)
}

Then select GorillaMuxAdapter into 3 different code paths:

  1. Version1 Unmarshal successful
  2. Version2 Unmarshal successful
  3. Failed to match event

Some of the tests were using the wrong stucture.

Cookies were not handled correctly for V2.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

richardstrnad commented 2 years ago

Just ran into the Cookie issue myself, any chance that this PR gets approved? If not, would you approve one with just the Cookie fix in it?

@aubelsb2 Thanks for the fix, really helped to not be stuck 👍

aubelsb2 commented 2 years ago

@richardstrnad If I knew it was going to be reviewed and merged I would put more effort into splitting it up. But I haven't heard anything

mxfactorial commented 2 years ago

no issues after deploying a graphql lambda in https://github.com/systemaccounting/mxfactorial/pull/233

thank you