fixed v4 chages
Some checks failed
lint / lint (pull_request) Failing after 1m21s
test / test (pull_request) Successful in 3m3s

This commit is contained in:
2025-02-20 19:11:27 +03:00
parent b224e80b80
commit c031230888
6 changed files with 116 additions and 21 deletions

19
http.go
View File

@@ -304,7 +304,7 @@ func (h *httpClient) newCodec(ct string) (codec.Codec, error) {
return nil, codec.ErrUnknownContentType
}
func (h *httpClient) Init(opts ...options.Option) error {
func (h *httpClient) Init(opts ...client.Option) error {
if len(opts) == 0 && h.init {
return nil
}
@@ -332,11 +332,11 @@ func (h *httpClient) Options() client.Options {
return h.opts
}
func (h *httpClient) NewRequest(service, method string, req interface{}, opts ...options.Option) client.Request {
func (h *httpClient) NewRequest(service, method string, req interface{}, opts ...client.RequestOption) client.Request {
return newHTTPRequest(service, method, req, h.opts.ContentType, opts...)
}
func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...options.Option) error {
func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error {
// make a copy of call opts
callOpts := h.opts.CallOptions
for _, opt := range opts {
@@ -353,7 +353,8 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
} else {
// got a deadline so no need to setup context
// but we need to set the timeout we pass along
if err := options.Set(&callOpts, time.Until(d), ".RequestTimeout"); err != nil {
o := options.NewOption("RequestTimeout")(time.Until(d))
if err := options.Apply(&callOpts, o); err != nil {
return errors.New("go.micro.client", fmt.Sprintf("%v", err.Error()), 400)
}
}
@@ -469,7 +470,7 @@ func (h *httpClient) Call(ctx context.Context, req client.Request, rsp interface
return gerr
}
func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...options.Option) (client.Stream, error) {
func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error) {
var err error
// make a copy of call opts
@@ -488,7 +489,8 @@ func (h *httpClient) Stream(ctx context.Context, req client.Request, opts ...opt
} else {
// got a deadline so no need to setup context
// but we need to set the timeout we pass along
if err = options.Set(&callOpts, time.Until(d), ".StreamTimeout"); err != nil {
o := options.NewOption("StreamTimeout")(time.Until(d))
if err := options.Apply(&callOpts, o); err != nil {
return nil, errors.New("go.micro.client", fmt.Sprintf("%v", err.Error()), 400)
}
}
@@ -618,7 +620,7 @@ func (h *httpClient) Name() string {
return h.opts.Name
}
func NewClient(opts ...options.Option) client.Client {
func NewClient(opts ...client.Option) client.Client {
options := client.NewOptions(opts...)
if len(options.ContentType) == 0 {
@@ -666,7 +668,6 @@ func NewClient(opts ...options.Option) client.Client {
}
rc.httpcli = &http.Client{Transport: tr}
}
c := client.Client(rc)
return c
return rc
}