Files
netbird/relay/healthcheck/ws.go
Zoltan Papp d2e48d4f5e [relay] Use instanceURL instead of Exposed address. (#4905)
Replaces string-based exposed address handling with URL-based InstanceURL() (type url.URL) across relay/server and relay/healthcheck; adds SchemeREL/SchemeRELS constants; updates getInstanceURL to return *url.URL with scheme and TLS validation; adjusts WS dialing and health-check logic to use URL fields.
2025-12-03 18:42:53 +01:00

37 lines
731 B
Go

package healthcheck
import (
"context"
"fmt"
"net/url"
"github.com/coder/websocket"
"github.com/netbirdio/netbird/relay/server"
"github.com/netbirdio/netbird/shared/relay"
)
func dialWS(ctx context.Context, address url.URL) error {
scheme := "ws"
if address.Scheme == server.SchemeRELS {
scheme = "wss"
}
wsURL := fmt.Sprintf("%s://%s%s", scheme, address.Host, relay.WebSocketURLPath)
conn, resp, err := websocket.Dial(ctx, wsURL, nil)
if resp != nil {
defer func() {
if resp.Body != nil {
_ = resp.Body.Close()
}
}()
}
if err != nil {
return fmt.Errorf("failed to connect to websocket: %w", err)
}
_ = conn.Close(websocket.StatusNormalClosure, "availability check complete")
return nil
}