labstack / echo

High performance, minimalist Go web framework
https://echo.labstack.com
MIT License
29.01k stars 2.21k forks source link

Is there any plan to facilitate responses in the Protobuf data format? #2628

Closed freeeverett closed 2 months ago

freeeverett commented 2 months ago

Is there any plan to facilitate responses in the Protobuf data format?

aldas commented 2 months ago

At the moment no. This would mean introducing oppinionated 3rd party dependency.

You can always create small helper function to marshal messages and write them to response.

Something like that (I have not tried it)

func Protobuf(c echo.Context, statusCode int, message proto.Message) error {
    b, err := proto.Marshal(message)
    if err != nil {
        return err
    }

    r := c.Response()
    r.Header().Add(echo.HeaderContentType, "application/x-protobuf")
    r.WriteHeader(statusCode)
    _, err = r.Write(b)
    return err
}
freeeverett commented 2 months ago

Thanks