Orion icon indicating copy to clipboard operation
Orion copied to clipboard

Encoder and Decoder concept seems opposite

Open achichen opened this issue 2 years ago • 2 comments

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 avatar May 29 '22 21:05 achichen

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

achichen avatar May 29 '22 22:05 achichen

cc @carousell/backend-framework

achichen avatar May 29 '22 22:05 achichen