Skip to content

Commit

Permalink
Merge pull request go-kit#538 from bcho/fix-example/set-header
Browse files Browse the repository at this point in the history
fix(example/shipping): header should set before `WriteHeader`
  • Loading branch information
peterbourgon authored May 26, 2017
2 parents 8280314 + 823ab61 commit 831fdeb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion shipping/booking/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ type errorer interface {

// encode errors from business-logic
func encodeError(_ context.Context, err error, w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
switch err {
case cargo.ErrUnknown:
w.WriteHeader(http.StatusNotFound)
Expand All @@ -187,7 +188,6 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {
default:
w.WriteHeader(http.StatusInternalServerError)
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(map[string]interface{}{
"error": err.Error(),
})
Expand Down
2 changes: 1 addition & 1 deletion shipping/handling/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type errorer interface {

// encode errors from business-logic
func encodeError(_ context.Context, err error, w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
switch err {
case cargo.ErrUnknown:
w.WriteHeader(http.StatusNotFound)
Expand All @@ -93,7 +94,6 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {
default:
w.WriteHeader(http.StatusInternalServerError)
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(map[string]interface{}{
"error": err.Error(),
})
Expand Down
2 changes: 1 addition & 1 deletion shipping/tracking/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type errorer interface {

// encode errors from business-logic
func encodeError(_ context.Context, err error, w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
switch err {
case cargo.ErrUnknown:
w.WriteHeader(http.StatusNotFound)
Expand All @@ -67,7 +68,6 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {
default:
w.WriteHeader(http.StatusInternalServerError)
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(map[string]interface{}{
"error": err.Error(),
})
Expand Down

0 comments on commit 831fdeb

Please sign in to comment.