feat(protocol): allow override of dial func

This commit is contained in:
2024-08-05 18:10:19 +02:00
parent b976bde363
commit 6842d4d88a
16 changed files with 158 additions and 18 deletions

View File

@ -2,6 +2,7 @@ package v2
import (
"context"
"net/http"
"sync"
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
@ -17,6 +18,10 @@ type Operations struct {
client *socketio.Client
mutex sync.RWMutex
logger logger.Logger
dial protocol.DialFunc
getClientOnce sync.Once
httpClient *http.Client
}
// Reboot implements protocol.Operations.
@ -161,12 +166,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)))
if err := client.Connect(); err != nil {
return errors.WithStack(err)