feat(protocol): allow override of dial func
This commit is contained in:
@ -6,6 +6,7 @@ func init() {
|
||||
protocol.Register(Identifier, func(opts *protocol.ProtocolOptions) (protocol.Protocol, error) {
|
||||
return &Protocol{
|
||||
logger: opts.Logger,
|
||||
dial: opts.Dial,
|
||||
}, nil
|
||||
})
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ type Operations struct {
|
||||
client *socketio.Client
|
||||
mutex sync.RWMutex
|
||||
logger logger.Logger
|
||||
|
||||
dial protocol.DialFunc
|
||||
}
|
||||
|
||||
// Close implements protocol.Operations.
|
||||
@ -49,12 +51,12 @@ func (o *Operations) Connect(ctx context.Context) error {
|
||||
o.client.Close()
|
||||
}
|
||||
|
||||
endpoint, err := socketio.EndpointFromHAddr(o.addr)
|
||||
endpoint, err := socketio.EndpointFromAddr(o.addr)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
client := socketio.NewClient(endpoint)
|
||||
client := socketio.NewClient(endpoint, socketio.WithDialFunc(socketio.DialFunc(o.dial)))
|
||||
|
||||
o.logger.Debug("connecting", logger.Attr("endpoint", endpoint))
|
||||
|
||||
|
@ -16,6 +16,7 @@ const compatibleVersionConstraint = "^2.24"
|
||||
|
||||
type Protocol struct {
|
||||
logger logger.Logger
|
||||
dial protocol.DialFunc
|
||||
}
|
||||
|
||||
// Available implements protocol.Protocol.
|
||||
@ -59,7 +60,7 @@ func (p *Protocol) Identifier() protocol.Identifier {
|
||||
|
||||
// Operations implements protocol.Protocol.
|
||||
func (p *Protocol) Operations(addr string) protocol.Operations {
|
||||
return &Operations{addr: addr, logger: p.logger}
|
||||
return &Operations{addr: addr, logger: p.logger, dial: p.dial}
|
||||
}
|
||||
|
||||
var _ protocol.Protocol = &Protocol{}
|
||||
|
Reference in New Issue
Block a user