mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
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.
37 lines
731 B
Go
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
|
|
}
|