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

Refactor HTTP handler #72

Merged
merged 3 commits into from
May 31, 2016
Merged

Refactor HTTP handler #72

merged 3 commits into from
May 31, 2016

Conversation

akshayjshah
Copy link
Contributor

Refactor @pravj's HTTP handler a little - the core of the code is the same, but I rearranged things a bit.

  • Create a struct for the handler, which makes it easier to separate the get and put logic.
  • Return JSON even for non-200 responses.
  • Leverage the Level type's UnmarshalText method.
  • Use the spy logger instead of a JSON logger in these tests.

var p httpPayload
decoder := json.NewDecoder(r.Body)
if err := decoder.Decode(&p); err != nil {
h.error(w, "Request body must be well-formed JSON.", http.StatusBadRequest)
Copy link
Collaborator

Choose a reason for hiding this comment

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

optional nit: should we put err into the error message being returned?

@prashantv
Copy link
Collaborator

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants