labstack / echo

High performance, minimalist Go web framework

Home Page:https://echo.labstack.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

freeeverett opened this issue · comments

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

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
}

Thanks