lifadev / archive_aws-lambda-go-shim

Author your AWS Lambda functions in Go, effectively.
https://github.com/eawsy/aws-lambda-go-shim
Apache License 2.0
789 stars 66 forks source link

Use a custom Marshaler #30

Closed ashinohara closed 7 years ago

ashinohara commented 7 years ago

I would like to be able to return protobuf marshaled as json back from the Handle function. I know that the current handler calls json.Marshal on the value returned from the lambda. Is there a way to easily override this behavior and use the json marshaler in protobufs instead?

fsenart commented 7 years ago

Hi @ashinohara, As you've noticed any value returned by the Handler is marshaled into JSON:

func Handle (evt json.RawMessage, ctx *runtime.Context) (*CustomType, error) { ... }

Also, if your CustomType satisfies the JSON Marshaler interface then it will be automatically processed by the shim. So I advocate on wrapping/modifying your protobuf type to implement this interface.

ashinohara commented 7 years ago

@fsenart Thanks for the quick response, I will give that a try!