Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 2.02 KB

README.md

File metadata and controls

53 lines (41 loc) · 2.02 KB

restencoder

Go Reference Go Report Card Builds

A optioned REST response encoder compatible with Go's standard lib.

Installation

go get github.com/caiorcferreira/restencoder

Usage

Success response

restencoder.Respond(
    w,
    StatusCode(http.StatusCreated),
    Header("X-Header", "value"),
    JSONBody(body),
)

Failure response

restencoder.Respond(
    w,
    StatusCode(http.StatusBadRequest),
    Header("X-Header", "value"),
    Error(err),
)

If you want a different failure response schema, you could implement your own restencoder.ResponseOption to define ResponseConfig.JSONBody to your failure response struct.

Contributing

Every help is always welcome. Feel free do throw us a pull request, we'll do our best to check it out as soon as possible. But before that, let us establish some guidelines:

  1. This is an open source project so please do not add any proprietary code or infringe any copyright of any sort.
  2. Avoid unnecessary dependencies or messing up go.mod file.
  3. Be aware of golang coding style. Use a lint to help you out.
  4. Add tests to cover your contribution.
  5. Use meaningful messages to your commits.
  6. Use pull requests.
  7. At last, but also important, be kind and polite with the community.

Any submitted issue which disrespect one or more guidelines above, will be discarded and closed.

License

Released under the MIT License.