2021-01-10 14:48:10 +03:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/unistack-org/micro/v3/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// DefaultPoolMaxStreams maximum streams on a connectioin
|
|
|
|
// (20)
|
|
|
|
DefaultPoolMaxStreams = 20
|
|
|
|
|
|
|
|
// DefaultPoolMaxIdle maximum idle conns of a pool
|
|
|
|
// (50)
|
|
|
|
DefaultPoolMaxIdle = 50
|
|
|
|
|
|
|
|
// DefaultMaxRecvMsgSize maximum message that client can receive
|
|
|
|
// (4 MB).
|
|
|
|
DefaultMaxRecvMsgSize = 1024 * 1024 * 4
|
|
|
|
|
|
|
|
// DefaultMaxSendMsgSize maximum message that client can send
|
|
|
|
// (4 MB).
|
|
|
|
DefaultMaxSendMsgSize = 1024 * 1024 * 4
|
|
|
|
)
|
|
|
|
|
|
|
|
type poolMaxStreams struct{}
|
|
|
|
|
2021-03-26 15:48:39 +03:00
|
|
|
// PoolMaxStreams maximum streams on a connectioin
|
2021-01-10 14:48:10 +03:00
|
|
|
func PoolMaxStreams(n int) client.Option {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetOption(poolMaxStreams{}, n)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
2021-04-25 16:18:54 +03:00
|
|
|
type poolMaxIdle struct{}
|
|
|
|
|
2021-03-26 15:48:39 +03:00
|
|
|
// PoolMaxIdle maximum idle conns of a pool
|
2021-01-10 14:48:10 +03:00
|
|
|
func PoolMaxIdle(d int) client.Option {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetOption(poolMaxIdle{}, d)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
2021-04-25 16:18:54 +03:00
|
|
|
type maxRecvMsgSizeKey struct{}
|
|
|
|
|
2021-01-10 14:48:10 +03:00
|
|
|
// MaxRecvMsgSize set the maximum size of message that client can receive.
|
|
|
|
func MaxRecvMsgSize(s int) client.Option {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetOption(maxRecvMsgSizeKey{}, s)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
2021-04-25 16:18:54 +03:00
|
|
|
type maxSendMsgSizeKey struct{}
|
|
|
|
|
2021-01-10 14:48:10 +03:00
|
|
|
// MaxSendMsgSize set the maximum size of message that client can send.
|
|
|
|
func MaxSendMsgSize(s int) client.Option {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetOption(maxSendMsgSizeKey{}, s)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type httpClientKey struct{}
|
|
|
|
|
2021-04-25 16:18:54 +03:00
|
|
|
// nolint: golint
|
2021-01-10 14:48:10 +03:00
|
|
|
func HTTPClient(c *http.Client) client.Option {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetOption(httpClientKey{}, c)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type httpDialerKey struct{}
|
|
|
|
|
2021-04-25 16:18:54 +03:00
|
|
|
// nolint: golint
|
2021-01-10 14:48:10 +03:00
|
|
|
func HTTPDialer(d *net.Dialer) client.Option {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetOption(httpDialerKey{}, d)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type methodKey struct{}
|
|
|
|
|
|
|
|
func Method(m string) client.CallOption {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetCallOption(methodKey{}, m)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type pathKey struct{}
|
|
|
|
|
|
|
|
func Path(p string) client.CallOption {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetCallOption(pathKey{}, p)
|
|
|
|
}
|
|
|
|
|
|
|
|
type bodyKey struct{}
|
|
|
|
|
|
|
|
func Body(b string) client.CallOption {
|
|
|
|
return client.SetCallOption(bodyKey{}, b)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type errorMapKey struct{}
|
|
|
|
|
|
|
|
func ErrorMap(m map[string]interface{}) client.CallOption {
|
2021-01-19 04:12:31 +03:00
|
|
|
return client.SetCallOption(errorMapKey{}, m)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
2021-03-23 00:29:27 +03:00
|
|
|
|
|
|
|
type structTagsKey struct{}
|
|
|
|
|
|
|
|
func StructTags(tags []string) client.CallOption {
|
|
|
|
return client.SetCallOption(structTagsKey{}, tags)
|
|
|
|
}
|