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

Extend content negotiation functionality #47

Merged
merged 12 commits into from
Mar 31, 2020

Conversation

joe94
Copy link
Member

@joe94 joe94 commented Mar 4, 2020

This PR adds convenience functions for a WRP handler's content negotiation strategy.

@joe94 joe94 requested a review from johnabass March 4, 2020 22:25
@codecov-io
Copy link

codecov-io commented Mar 4, 2020

Codecov Report

Merging #47 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #47   +/-   ##
=======================================
  Coverage   46.61%   46.61%           
=======================================
  Files          15       15           
  Lines        3152     3152           
=======================================
  Hits         1469     1469           
  Misses       1521     1521           
  Partials      162      162
Impacted Files Coverage Δ
wrphttp/requestResponse.go 94.59% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8629d45...c30c7a0. Read the comment docs.

@joe94 joe94 changed the title add content-type for wrp response type negotiation Extend content negotiation functionality Mar 27, 2020
@joe94 joe94 self-assigned this Mar 27, 2020
@joe94 joe94 requested a review from kristinapathak March 27, 2020 18:02
encoder = wrp.NewEncoderBytes(&output, erw.f)
)
func (erw *entityResponseWriter) WriteWRP(e *Entity) (int, error) {
if e == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, you don't need to do this. It's ok to allow panics on nil. That indicates a bug in the calling code, which you don't want to mask with a "normal" call return.

}

erw.ResponseWriter.Header().Set("Content-Type", erw.f.ContentType())
return erw.ResponseWriter.Write(output)
}

func (erw *entityResponseWriter) WriteWRPFromBytes(f wrp.Format, encodedWRP []byte) (int, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general naming convention, words like "from" are avoided in golang APIs. This can be just WriteWRPBytes.

@joe94 joe94 merged commit cbb4fba into master Mar 31, 2020
@joe94 joe94 deleted the feature/contentTypeNegotiation branch March 31, 2020 18:11
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

Successfully merging this pull request may close these issues.

5 participants