lifadev / archive_aws-lambda-go-shim

Author your AWS Lambda functions in Go, effectively.

Home Page:https://github.com/eawsy/aws-lambda-go-shim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use a custom Marshaler

ashinohara opened this issue · comments

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?

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.

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