feat: add httpc.Do & httpc.Service.Do (#1775)
* backup * backup * backup * feat: add httpc.Do & httpc.Service.Do * fix: not using strings.Cut, it's from Go 1.18 * chore: remove redudant code * feat: httpc.Do finished * chore: fix reviewdog * chore: break loop if found * add more tests
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package httpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/breaker"
|
||||
@@ -12,6 +13,8 @@ type (
|
||||
|
||||
// Service represents a remote HTTP service.
|
||||
Service interface {
|
||||
// Do sends an HTTP request with the given arguments and returns an HTTP response.
|
||||
Do(ctx context.Context, method, url string, data interface{}) (*http.Response, error)
|
||||
// DoRequest sends a HTTP request to the service.
|
||||
DoRequest(r *http.Request) (*http.Response, error)
|
||||
}
|
||||
@@ -39,6 +42,16 @@ func NewServiceWithClient(name string, cli *http.Client, opts ...Option) Service
|
||||
}
|
||||
}
|
||||
|
||||
// Do sends an HTTP request with the given arguments and returns an HTTP response.
|
||||
func (s namedService) Do(ctx context.Context, method, url string, data interface{}) (*http.Response, error) {
|
||||
req, err := buildRequest(ctx, method, url, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.DoRequest(req)
|
||||
}
|
||||
|
||||
// DoRequest sends an HTTP request to the service.
|
||||
func (s namedService) DoRequest(r *http.Request) (*http.Response, error) {
|
||||
return request(r, s)
|
||||
|
||||
Reference in New Issue
Block a user