Skip to content

Commit

Permalink
add NewClientWithError
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienTant committed Oct 11, 2019
1 parent 2ee51f0 commit 1333bc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ func NewClient(
return &Client{Client: kithttp.NewClient(method, tgt, enc, makeDecodeResponseFunc(dec), options...)}
}

// NewClientWithError creates a kitty client that decode error.
func NewClientWithError(
method string,
tgt *url.URL,
enc kithttp.EncodeRequestFunc,
dec kithttp.DecodeResponseFunc,
options ...kithttp.ClientOption,
) *Client {
return &Client{Client: kithttp.NewClient(method, tgt, enc, dec, options...)}
}

// makeDecodeResponseFunc maps HTTP errors to Go errors.
func makeDecodeResponseFunc(fn kithttp.DecodeResponseFunc) kithttp.DecodeResponseFunc {
return func(ctx context.Context, resp *http.Response) (interface{}, error) {
Expand All @@ -36,4 +47,4 @@ func makeDecodeResponseFunc(fn kithttp.DecodeResponseFunc) kithttp.DecodeRespons
}
return fn(ctx, resp)
}
}
}
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ github.com/go-logfmt/logfmt v0.4.0 h1:MP4Eh7ZCb31lleYCFuwm0oe4/YGak+5l1vA2NOE80n
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sony/gobreaker v0.4.1 h1:oMnRNZXX5j85zso6xCPRNPtmAycat+WcoKbklScLDgQ=
Expand Down

0 comments on commit 1333bc4

Please sign in to comment.