Transport init
This commit is contained in:
parent
f088074f29
commit
5a6ff655db
@ -118,7 +118,7 @@ var (
|
||||
"random": selector.NewSelector,
|
||||
}
|
||||
|
||||
DefaultTransports = map[string]func([]string, ...transport.Option) transport.Transport{
|
||||
DefaultTransports = map[string]func(...transport.Option) transport.Transport{
|
||||
"http": transport.NewTransport,
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
if t, ok := c.opts.Transports[name]; ok {
|
||||
n := t(strings.Split(ctx.String("transport_address"), ","))
|
||||
n := t(transport.Addrs(strings.Split(ctx.String("transport_address"), ",")...))
|
||||
*c.opts.Transport = n
|
||||
} else {
|
||||
return fmt.Errorf("Transport %s not found", name)
|
||||
|
@ -28,7 +28,7 @@ type Options struct {
|
||||
Brokers map[string]func(...broker.Option) broker.Broker
|
||||
Registries map[string]func(...registry.Option) registry.Registry
|
||||
Selectors map[string]func(...selector.Option) selector.Selector
|
||||
Transports map[string]func([]string, ...transport.Option) transport.Transport
|
||||
Transports map[string]func(...transport.Option) transport.Transport
|
||||
|
||||
// Other options for implementations of the interface
|
||||
// can be stored in a context
|
||||
@ -114,7 +114,7 @@ func NewSelector(name string, s func(...selector.Option) selector.Selector) Opti
|
||||
}
|
||||
|
||||
// New transport func
|
||||
func NewTransport(name string, t func([]string, ...transport.Option) transport.Transport) Option {
|
||||
func NewTransport(name string, t func(...transport.Option) transport.Transport) Option {
|
||||
return func(o *Options) {
|
||||
o.Transports[name] = t
|
||||
}
|
||||
|
@ -9,6 +9,6 @@ func init() {
|
||||
cmd.DefaultTransports["http"] = NewTransport
|
||||
}
|
||||
|
||||
func NewTransport(addrs []string, opts ...transport.Option) transport.Transport {
|
||||
return transport.NewTransport(addrs, opts...)
|
||||
func NewTransport(opts ...transport.Option) transport.Transport {
|
||||
return transport.NewTransport(opts...)
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ func (h *httpTransport) String() string {
|
||||
return "http"
|
||||
}
|
||||
|
||||
func newHttpTransport(addrs []string, opts ...Option) *httpTransport {
|
||||
func newHttpTransport(opts ...Option) *httpTransport {
|
||||
var options Options
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
|
@ -18,7 +18,7 @@ func expectedPort(t *testing.T, expected string, lsn transport.Listener) {
|
||||
}
|
||||
|
||||
func TestHTTPTransportPortRange(t *testing.T) {
|
||||
tp := transport.NewTransport([]string{})
|
||||
tp := transport.NewTransport()
|
||||
|
||||
lsn1, err := tp.Listen(":44444-44448")
|
||||
if err != nil {
|
||||
@ -43,7 +43,7 @@ func TestHTTPTransportPortRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHTTPTransportCommunication(t *testing.T) {
|
||||
tr := transport.NewTransport([]string{})
|
||||
tr := transport.NewTransport()
|
||||
|
||||
l, err := tr.Listen(":0")
|
||||
if err != nil {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
type Options struct {
|
||||
Addrs []string
|
||||
Secure bool
|
||||
TLSConfig *tls.Config
|
||||
|
||||
@ -37,6 +38,13 @@ type ListenOptions struct {
|
||||
Context context.Context
|
||||
}
|
||||
|
||||
// Addrs to use for transport
|
||||
func Addrs(addrs ...string) Option {
|
||||
return func(o *Options) {
|
||||
o.Addrs = addrs
|
||||
}
|
||||
}
|
||||
|
||||
// Use secure communication. If TLSConfig is not specified we
|
||||
// use InsecureSkipVerify and generate a self signed cert
|
||||
func Secure(b bool) Option {
|
||||
|
@ -43,13 +43,13 @@ type DialOption func(*DialOptions)
|
||||
type ListenOption func(*ListenOptions)
|
||||
|
||||
var (
|
||||
DefaultTransport Transport = newHttpTransport([]string{})
|
||||
DefaultTransport Transport = newHttpTransport()
|
||||
|
||||
DefaultDialTimeout = time.Second * 5
|
||||
)
|
||||
|
||||
func NewTransport(addrs []string, opt ...Option) Transport {
|
||||
return newHttpTransport(addrs, opt...)
|
||||
func NewTransport(opts ...Option) Transport {
|
||||
return newHttpTransport(opts...)
|
||||
}
|
||||
|
||||
func Dial(addr string, opts ...DialOption) (Client, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user