prepare options
Some checks failed
lint / lint (pull_request) Failing after 1m20s
test / test (pull_request) Successful in 1m59s

This commit is contained in:
2025-02-21 20:13:34 +03:00
parent c031230888
commit 334a10e26d
2 changed files with 20 additions and 52 deletions

View File

@@ -6,7 +6,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
@@ -199,7 +199,7 @@ func newRequest(ctx context.Context, log logger.Logger, addr string, req client.
var hreq *http.Request
if len(b) > 0 {
hreq, err = http.NewRequestWithContext(ctx, method, u.String(), ioutil.NopCloser(bytes.NewBuffer(b)))
hreq, err = http.NewRequestWithContext(ctx, method, u.String(), io.NopCloser(bytes.NewBuffer(b)))
hreq.ContentLength = int64(len(b))
header.Set("Content-Length", fmt.Sprintf("%d", hreq.ContentLength))
} else {

View File

@@ -1,7 +1,6 @@
package http
import (
"go.unistack.org/micro/v4/client"
"net"
"net/http"
@@ -27,104 +26,73 @@ var (
DefaultMaxSendMsgSize = 1024 * 1024 * 4
)
type poolMaxStreams struct{}
// PoolMaxStreams maximum streams on a connectioin
func PoolMaxStreams(n int) options.Option {
return func(i interface{}) error {
}
return options.ContextOption(poolMaxStreams{}, n)
return options.NewOption("PoolMaxStreams")(n)
}
type poolMaxIdle struct{}
// PoolMaxIdle maximum idle conns of a pool
func PoolMaxIdle(d int) options.Option {
return options.ContextOption(poolMaxIdle{}, d)
func PoolMaxIdle(n int) options.Option {
return options.NewOption("PoolMaxIdle")(n)
}
type maxRecvMsgSizeKey struct{}
// MaxRecvMsgSize set the maximum size of message that client can receive.
func MaxRecvMsgSize(s int) options.Option {
return options.ContextOption(maxRecvMsgSizeKey{}, s)
func MaxRecvMsgSize(n int) options.Option {
return options.NewOption("MaxRecvMsgSize")(n)
}
type maxSendMsgSizeKey struct{}
// MaxSendMsgSize set the maximum size of message that client can send.
func MaxSendMsgSize(s int) options.Option {
return options.ContextOption(maxSendMsgSizeKey{}, s)
func MaxSendMsgSize(n int) options.Option {
return options.NewOption("MaxSendMsgSize")(n)
}
type httpClientKey struct{}
// nolint: golint
// HTTPClient pass http.Client option to client Call
func HTTPClient(c *http.Client) options.Option {
return options.ContextOption(httpClientKey{}, c)
return options.NewOption("HTTPClient")(c)
}
type httpDialerKey struct{}
// nolint: golint
// HTTPDialer pass net.Dialer option to client
func HTTPDialer(d *net.Dialer) options.Option {
return options.ContextOption(httpDialerKey{}, d)
return options.NewOption("HTTPDialer")(d)
}
type methodKey struct{}
// Method pass method option to client Call
func Method(m string) client.CallOptions {
return options.Context(methodKey{}, m)
func Method(m string) options.Option {
return options.NewOption("Method")(m)
}
type pathKey struct{}
// Path spcecifies path option to client Call
func Path(p string) options.Option {
return options.ContextOption(pathKey{}, p)
return options.NewOption("Path")(p)
}
type bodyKey struct{}
// Body specifies body option to client Call
func Body(b string) options.Option {
return options.ContextOption(bodyKey{}, b)
return options.NewOption("Body")(b)
}
type errorMapKey struct{}
func ErrorMap(m map[string]interface{}) options.Option {
return options.ContextOption(errorMapKey{}, m)
return options.NewOption("ErrorMap")(m)
}
type structTagsKey struct{}
// StructTags pass tags slice option to client Call
func StructTags(tags []string) options.Option {
return options.ContextOption(structTagsKey{}, tags)
return options.NewOption("StructTags")(tags)
}
type metadataKey struct{}
// Metadata pass metadata to client Call
func Metadata(md metadata.Metadata) options.Option {
return options.ContextOption(metadataKey{}, md)
return options.NewOption("Metadata")(md)
}
type cookieKey struct{}
// Cookie pass cookie to client Call
func Cookie(cookies ...string) options.Option {
return options.ContextOption(cookieKey{}, cookies)
return options.NewOption("Cookie")(cookies)
}
type headerKey struct{}
// Header pass cookie to client Call
func Header(headers ...string) options.Option {
return options.ContextOption(headerKey{}, headers)
return options.NewOption("Header")(headers)
}