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

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

Closed
freeeverett opened this issue Apr 24, 2024 · 2 comments
Closed

Comments

@freeeverett
Copy link

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

@aldas
Copy link
Contributor

aldas commented Apr 24, 2024

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
Copy link
Author

Thanks

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

2 participants