Skip to content

Commit

Permalink
feat(httpc): added MetricsInterceptor in DoRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
Suyghur authored and kevwan committed Aug 6, 2024
1 parent 4196ddb commit f1d8a19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion rest/httpc/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ func Do(ctx context.Context, method, url string, data any) (*http.Response, erro

// DoRequest sends an HTTP request and returns an HTTP response.
func DoRequest(r *http.Request) (*http.Response, error) {
return request(r, defaultClient{})
interceptor := internal.MetricsInterceptor("", nil)
r, handler := interceptor(r)
resp, err := request(r, defaultClient{})
handler(resp, err)
return resp, err
}

type (
Expand Down
7 changes: 6 additions & 1 deletion rest/httpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

"github.com/zeromicro/go-zero/core/breaker"
"github.com/zeromicro/go-zero/rest/httpc/internal"
)

type (
Expand Down Expand Up @@ -54,7 +55,11 @@ func (s namedService) Do(ctx context.Context, method, url string, data any) (*ht

// DoRequest sends an HTTP request to the service.
func (s namedService) DoRequest(r *http.Request) (*http.Response, error) {
return request(r, s)
interceptor := internal.MetricsInterceptor(s.name, nil)
r, handler := interceptor(r)
resp, err := request(r, s)
handler(resp, err)
return resp, err
}

func (s namedService) do(r *http.Request) (resp *http.Response, err error) {
Expand Down

0 comments on commit f1d8a19

Please sign in to comment.