handshake and connect in constructor

This commit is contained in:
Marcelo Pires 2018-09-05 11:04:10 +02:00
parent 554909ee53
commit 8dd8da2307

View File

@ -41,11 +41,19 @@ func NewClient(url string, opts ...Option) (*Client, error) {
InExt: c.opts.inExt, InExt: c.opts.inExt,
OutExt: c.opts.outExt, OutExt: c.opts.outExt,
} }
var err error
err := c.opts.transport.Init(tops) if err = c.opts.transport.Init(tops); err != nil {
if err != nil {
return nil, err return nil, err
} }
if err = c.opts.transport.Handshake(); err != nil {
return nil, err
}
if err = c.opts.transport.Connect(); err != nil {
return nil, err
}
return &c, nil return &c, nil
} }
@ -60,6 +68,7 @@ func WithInExtension(extension message.Extension) Option {
o.inExt = extension o.inExt = extension
} }
} }
func WithTransport(t transport.Transport) Option { func WithTransport(t transport.Transport) Option {
return func(o *options) { return func(o *options) {
o.transport = t o.transport = t