revert and update options && fix linter
This commit is contained in:
157
options.go
157
options.go
@@ -1,11 +1,12 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"go.unistack.org/micro/v4/client"
|
||||
"go.unistack.org/micro/v4/metadata"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -26,73 +27,171 @@ var (
|
||||
DefaultMaxSendMsgSize = 1024 * 1024 * 4
|
||||
)
|
||||
|
||||
type poolMaxStreams struct{}
|
||||
|
||||
// PoolMaxStreams maximum streams on a connectioin
|
||||
func PoolMaxStreams(n int) options.Option {
|
||||
return options.NewOption("PoolMaxStreams")(n)
|
||||
func PoolMaxStreams(n int) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, poolMaxStreams{}, n)
|
||||
}
|
||||
}
|
||||
|
||||
type poolMaxIdle struct{}
|
||||
|
||||
// PoolMaxIdle maximum idle conns of a pool
|
||||
func PoolMaxIdle(n int) options.Option {
|
||||
return options.NewOption("PoolMaxIdle")(n)
|
||||
func PoolMaxIdle(d int) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, poolMaxIdle{}, d)
|
||||
}
|
||||
}
|
||||
|
||||
type maxRecvMsgSizeKey struct{}
|
||||
|
||||
// MaxRecvMsgSize set the maximum size of message that client can receive.
|
||||
func MaxRecvMsgSize(n int) options.Option {
|
||||
return options.NewOption("MaxRecvMsgSize")(n)
|
||||
func MaxRecvMsgSize(s int) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, maxRecvMsgSizeKey{}, s)
|
||||
}
|
||||
}
|
||||
|
||||
type maxSendMsgSizeKey struct{}
|
||||
|
||||
// MaxSendMsgSize set the maximum size of message that client can send.
|
||||
func MaxSendMsgSize(n int) options.Option {
|
||||
return options.NewOption("MaxSendMsgSize")(n)
|
||||
func MaxSendMsgSize(s int) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, maxSendMsgSizeKey{}, s)
|
||||
}
|
||||
}
|
||||
|
||||
type httpClientKey struct{}
|
||||
|
||||
// nolint: golint
|
||||
// HTTPClient pass http.Client option to client Call
|
||||
func HTTPClient(c *http.Client) options.Option {
|
||||
return options.NewOption("HTTPClient")(c)
|
||||
func HTTPClient(c *http.Client) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, httpClientKey{}, c)
|
||||
}
|
||||
}
|
||||
|
||||
type httpDialerKey struct{}
|
||||
|
||||
// nolint: golint
|
||||
// HTTPDialer pass net.Dialer option to client
|
||||
func HTTPDialer(d *net.Dialer) options.Option {
|
||||
return options.NewOption("HTTPDialer")(d)
|
||||
func HTTPDialer(d *net.Dialer) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, httpDialerKey{}, d)
|
||||
}
|
||||
}
|
||||
|
||||
type methodKey struct{}
|
||||
|
||||
// Method pass method option to client Call
|
||||
func Method(m string) options.Option {
|
||||
return options.NewOption("Method")(m)
|
||||
func Method(m string) client.CallOption {
|
||||
return func(o *client.CallOptions) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, methodKey{}, m)
|
||||
}
|
||||
}
|
||||
|
||||
type pathKey struct{}
|
||||
|
||||
// Path spcecifies path option to client Call
|
||||
func Path(p string) options.Option {
|
||||
return options.NewOption("Path")(p)
|
||||
func Path(p string) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, pathKey{}, p)
|
||||
}
|
||||
}
|
||||
|
||||
type bodyKey struct{}
|
||||
|
||||
// Body specifies body option to client Call
|
||||
func Body(b string) options.Option {
|
||||
return options.NewOption("Body")(b)
|
||||
func Body(b string) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, bodyKey{}, b)
|
||||
}
|
||||
}
|
||||
|
||||
func ErrorMap(m map[string]interface{}) options.Option {
|
||||
return options.NewOption("ErrorMap")(m)
|
||||
type errorMapKey struct{}
|
||||
|
||||
func ErrorMap(m map[string]interface{}) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, errorMapKey{}, m)
|
||||
}
|
||||
}
|
||||
|
||||
type structTagsKey struct{}
|
||||
|
||||
// StructTags pass tags slice option to client Call
|
||||
func StructTags(tags []string) options.Option {
|
||||
return options.NewOption("StructTags")(tags)
|
||||
func StructTags(tags []string) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, structTagsKey{}, tags)
|
||||
}
|
||||
}
|
||||
|
||||
type metadataKey struct{}
|
||||
|
||||
// Metadata pass metadata to client Call
|
||||
func Metadata(md metadata.Metadata) options.Option {
|
||||
return options.NewOption("Metadata")(md)
|
||||
func Metadata(md metadata.Metadata) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, metadataKey{}, md)
|
||||
}
|
||||
}
|
||||
|
||||
type cookieKey struct{}
|
||||
|
||||
// Cookie pass cookie to client Call
|
||||
func Cookie(cookies ...string) options.Option {
|
||||
return options.NewOption("Cookie")(cookies)
|
||||
func Cookie(cookies ...string) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, cookieKey{}, cookies)
|
||||
}
|
||||
}
|
||||
|
||||
type headerKey struct{}
|
||||
|
||||
// Header pass cookie to client Call
|
||||
func Header(headers ...string) options.Option {
|
||||
return options.NewOption("Header")(headers)
|
||||
func Header(headers ...string) client.Option {
|
||||
return func(o *client.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
o.Context = context.WithValue(o.Context, headerKey{}, headers)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user