2021-01-10 14:48:10 +03:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
|
2023-04-28 22:29:18 +03:00
|
|
|
"go.unistack.org/micro/v4/metadata"
|
2023-08-12 13:17:47 +03:00
|
|
|
"go.unistack.org/micro/v4/options"
|
2021-01-10 14:48:10 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2023-08-12 13:17:47 +03:00
|
|
|
func PoolMaxStreams(n int) options.Option {
|
|
|
|
return options.ContextOption(poolMaxStreams{}, n)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
2021-04-25 16:26:36 +03:00
|
|
|
type poolMaxIdle struct{}
|
|
|
|
|
2021-03-26 15:48:39 +03:00
|
|
|
// PoolMaxIdle maximum idle conns of a pool
|
2023-08-12 13:17:47 +03:00
|
|
|
func PoolMaxIdle(d int) options.Option {
|
|
|
|
return options.ContextOption(poolMaxIdle{}, d)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
2021-04-25 16:26:36 +03:00
|
|
|
type maxRecvMsgSizeKey struct{}
|
|
|
|
|
2021-01-10 14:48:10 +03:00
|
|
|
// MaxRecvMsgSize set the maximum size of message that client can receive.
|
2023-08-12 13:17:47 +03:00
|
|
|
func MaxRecvMsgSize(s int) options.Option {
|
|
|
|
return options.ContextOption(maxRecvMsgSizeKey{}, s)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
2021-04-25 16:26:36 +03:00
|
|
|
type maxSendMsgSizeKey struct{}
|
|
|
|
|
2021-01-10 14:48:10 +03:00
|
|
|
// MaxSendMsgSize set the maximum size of message that client can send.
|
2023-08-12 13:17:47 +03:00
|
|
|
func MaxSendMsgSize(s int) options.Option {
|
|
|
|
return options.ContextOption(maxSendMsgSizeKey{}, s)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type httpClientKey struct{}
|
|
|
|
|
2021-04-25 16:26:36 +03:00
|
|
|
// nolint: golint
|
2021-10-25 19:59:37 +03:00
|
|
|
// HTTPClient pass http.Client option to client Call
|
2023-08-12 13:17:47 +03:00
|
|
|
func HTTPClient(c *http.Client) options.Option {
|
|
|
|
return options.ContextOption(httpClientKey{}, c)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type httpDialerKey struct{}
|
|
|
|
|
2021-04-25 16:26:36 +03:00
|
|
|
// nolint: golint
|
2021-10-25 19:59:37 +03:00
|
|
|
// HTTPDialer pass net.Dialer option to client
|
2023-08-12 13:17:47 +03:00
|
|
|
func HTTPDialer(d *net.Dialer) options.Option {
|
|
|
|
return options.ContextOption(httpDialerKey{}, d)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type methodKey struct{}
|
|
|
|
|
2021-10-25 19:59:37 +03:00
|
|
|
// Method pass method option to client Call
|
2023-08-12 13:17:47 +03:00
|
|
|
func Method(m string) options.Option {
|
|
|
|
return options.ContextOption(methodKey{}, m)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type pathKey struct{}
|
|
|
|
|
2021-10-25 19:59:37 +03:00
|
|
|
// Path spcecifies path option to client Call
|
2023-08-12 13:17:47 +03:00
|
|
|
func Path(p string) options.Option {
|
|
|
|
return options.ContextOption(pathKey{}, p)
|
2021-01-19 04:12:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type bodyKey struct{}
|
|
|
|
|
2021-10-25 19:59:37 +03:00
|
|
|
// Body specifies body option to client Call
|
2023-08-12 13:17:47 +03:00
|
|
|
func Body(b string) options.Option {
|
|
|
|
return options.ContextOption(bodyKey{}, b)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type errorMapKey struct{}
|
|
|
|
|
2023-08-12 13:17:47 +03:00
|
|
|
func ErrorMap(m map[string]interface{}) options.Option {
|
|
|
|
return options.ContextOption(errorMapKey{}, m)
|
2021-01-10 14:48:10 +03:00
|
|
|
}
|
2021-03-23 00:29:27 +03:00
|
|
|
|
|
|
|
type structTagsKey struct{}
|
|
|
|
|
2021-10-25 19:59:37 +03:00
|
|
|
// StructTags pass tags slice option to client Call
|
2023-08-12 13:17:47 +03:00
|
|
|
func StructTags(tags []string) options.Option {
|
|
|
|
return options.ContextOption(structTagsKey{}, tags)
|
2021-03-23 00:29:27 +03:00
|
|
|
}
|
2021-07-09 11:00:19 +03:00
|
|
|
|
|
|
|
type metadataKey struct{}
|
|
|
|
|
2021-10-25 19:59:37 +03:00
|
|
|
// Metadata pass metadata to client Call
|
2023-08-12 13:17:47 +03:00
|
|
|
func Metadata(md metadata.Metadata) options.Option {
|
|
|
|
return options.ContextOption(metadataKey{}, md)
|
2021-07-09 11:00:19 +03:00
|
|
|
}
|
2021-10-25 19:59:37 +03:00
|
|
|
|
|
|
|
type cookieKey struct{}
|
|
|
|
|
|
|
|
// Cookie pass cookie to client Call
|
2023-08-12 13:17:47 +03:00
|
|
|
func Cookie(cookies ...string) options.Option {
|
|
|
|
return options.ContextOption(cookieKey{}, cookies)
|
2021-10-25 19:59:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type headerKey struct{}
|
|
|
|
|
|
|
|
// Header pass cookie to client Call
|
2023-08-12 13:17:47 +03:00
|
|
|
func Header(headers ...string) options.Option {
|
|
|
|
return options.ContextOption(headerKey{}, headers)
|
2021-10-25 19:59:37 +03:00
|
|
|
}
|