From f1d8a198b6dbe8b1f88f3bef49552346d6644d8b Mon Sep 17 00:00:00 2001 From: #Suyghur Date: Fri, 2 Aug 2024 21:06:48 +0800 Subject: [PATCH] feat(httpc): added `MetricsInterceptor` in `DoRequest` --- rest/httpc/requests.go | 6 +++++- rest/httpc/service.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/rest/httpc/requests.go b/rest/httpc/requests.go index 181b53e87b47..15136dd75bf7 100644 --- a/rest/httpc/requests.go +++ b/rest/httpc/requests.go @@ -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 ( diff --git a/rest/httpc/service.go b/rest/httpc/service.go index a65880e324ab..9831846624bf 100644 --- a/rest/httpc/service.go +++ b/rest/httpc/service.go @@ -5,6 +5,7 @@ import ( "net/http" "github.com/zeromicro/go-zero/core/breaker" + "github.com/zeromicro/go-zero/rest/httpc/internal" ) type ( @@ -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) {