Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoder and Decoder concept seems opposite #178

Open
achichen opened this issue May 29, 2022 · 2 comments
Open

Encoder and Decoder concept seems opposite #178

achichen opened this issue May 29, 2022 · 2 comments

Comments

@achichen
Copy link
Contributor

achichen commented May 29, 2022

Orion defines func prototypes Encoder and Decoder for handling http request/response as https://github.com/carousell/Orion/blob/master/orion/handlers/types.go#L40-L44:

//Encoder is the function type needed for request encoders
type Encoder func(req *http.Request, reqObject interface{}) error

//Decoder is the function type needed for response decoders
type Decoder func(ctx context.Context, w http.ResponseWriter, encodeError, endpointError error, respObject interface{})

Encoder extracts information from incoming http request and convert to a request object. Decoder takes a response object to write it into http response.

Essentially, Encoders does unmarshalling and deserializing action, while Decoders does marshalling and serializing. The name and what exactly it does seems opposite.

Even in Orion's code, we can find this confusion: https://github.com/carousell/Orion/blob/master/orion/handlers/http/http.go#L176-L188. In the beginning of the section, the comment says "decoder func", but it calls encoders later.

Should them switch names?

@achichen
Copy link
Contributor Author

@ankurs Do you have the context on why it was named so?

@achichen
Copy link
Contributor Author

cc @carousell/backend-framework

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant