Skip to content

Commit

Permalink
fix HTTPHandler typo
Browse files Browse the repository at this point in the history
  • Loading branch information
talgendler committed Nov 16, 2020
1 parent f161844 commit 48d77a9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ When you done, read the [documentation](https://github.com/go-masonry/tutorial)
* Log/Dump requests and/or responses when http request fails.

```golang
return func(req *http.Request, handler client.HTTPpHandler) (resp *http.Response, err error) {
return func(req *http.Request, handler client.HTTPHandler) (resp *http.Response, err error) {
var reqBytes, respBytes []byte
// If the response is Bad Request, log both Request and Response
reqBytes, _ = httputil.DumpRequestOut(req, true) // it can be nil and it's ok
Expand All @@ -57,7 +57,7 @@ When you done, read the [documentation](https://github.com/go-masonry/tutorial)
* Alter requests and/or responses (useful in [Tests](https://github.com/go-masonry/mortar-demo/blob/master/workshop/app/controllers/workshop_test.go#L162))

```golang
func(*http.Request, clientInt.HTTPpHandler) (*http.Response, error) {
func(*http.Request, clientInt.HTTPHandler) (*http.Response, error) {
// special case, don't go anywhere just return the response
return &http.Response{
Status: "200 OK",
Expand Down
4 changes: 2 additions & 2 deletions http/client/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ func (crt *customRoundTripper) RoundTrip(req *http.Request) (*http.Response, err

func uniteInterceptors(interceptors []client.HTTPClientInterceptor) client.HTTPClientInterceptor {
if len(interceptors) == 0 {
return func(req *http.Request, handler client.HTTPpHandler) (*http.Response, error) {
return func(req *http.Request, handler client.HTTPHandler) (*http.Response, error) {
// That's why we needed an alias to http.RoundTripper.RoundTrip
return handler(req)
}
}

return func(req *http.Request, handler client.HTTPpHandler) (*http.Response, error) {
return func(req *http.Request, handler client.HTTPHandler) (*http.Response, error) {
tailHandler := func(innerReq *http.Request) (*http.Response, error) {
unitedInterceptor := uniteInterceptors(interceptors[1:])
return unitedInterceptor(req, handler)
Expand Down
2 changes: 1 addition & 1 deletion http/client/httpclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestWithInterceptor(t *testing.T) {
require.Equal(t, "Pike", family)
}

func testInterceptor(req *http.Request, handler client.HTTPpHandler) (resp *http.Response, err error) {
func testInterceptor(req *http.Request, handler client.HTTPHandler) (resp *http.Response, err error) {
req.Header.Set("name", "Robert")
if resp, err = handler(req); err == nil {
resp.Header.Set("family", "Pike")
Expand Down
6 changes: 3 additions & 3 deletions interfaces/http/client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
// http.Client
//********************************************************************************

// HTTPpHandler is just an alias to http.RoundTriper.RoundTrip function
type HTTPpHandler func(*http.Request) (*http.Response, error)
// HTTPHandler is just an alias to http.RoundTriper.RoundTrip function
type HTTPHandler func(*http.Request) (*http.Response, error)

// HTTPClientInterceptor is a user defined function that can alter a request before it's sent
// and/or alter a response before it's returned to the caller
type HTTPClientInterceptor func(*http.Request, HTTPpHandler) (*http.Response, error)
type HTTPClientInterceptor func(*http.Request, HTTPHandler) (*http.Response, error)

// HTTPClientBuilder is a builder interface to build http.Client with interceptors
type HTTPClientBuilder interface {
Expand Down
2 changes: 1 addition & 1 deletion middleware/interceptors/trace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TracerGRPCClientInterceptor(deps tracingDeps) grpc.UnaryClientInterceptor {

// TracerRESTClientInterceptor is a REST tracing client interceptor, it can log req/resp if needed
func TracerRESTClientInterceptor(deps tracingDeps) client.HTTPClientInterceptor {
return func(req *http.Request, handler client.HTTPpHandler) (resp *http.Response, err error) {
return func(req *http.Request, handler client.HTTPHandler) (resp *http.Response, err error) {
if deps.Tracer == nil {
return handler(req)
}
Expand Down

0 comments on commit 48d77a9

Please sign in to comment.