Transport init

This commit is contained in:
Asim
2016-03-15 22:25:32 +00:00
parent f088074f29
commit 5a6ff655db
7 changed files with 20 additions and 12 deletions

View File

@@ -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...)
}

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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) {