refactor: websockets into 'connect' module, rename & adjust generally

This commit is contained in:
2025-08-01 20:34:45 -05:00
parent 102a4e7438
commit 9b8ef545a6
32 changed files with 202 additions and 149 deletions

View File

@@ -1,6 +1,7 @@
package internal
import (
"fmt"
"reflect"
"runtime"
"sync/atomic"
@@ -12,6 +13,10 @@ type EnabledDisabledInfo struct {
RunOnError bool
}
var (
currentVersion = "0.7.0"
)
var (
id atomic.Int64 // default value is 0
)
@@ -26,3 +31,20 @@ func NextId() int64 {
func GetFunctionName(i interface{}) string {
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
}
// GetEquivalentWebsocketScheme returns the equivalent websocket scheme for the given scheme.
// If the scheme is http or https, it returns ws or wss respectively.
// If the scheme is ws or wss, it returns the same scheme.
// If the scheme is not any of the above, it returns an error.
func GetEquivalentWebsocketScheme(scheme string) (string, error) {
switch scheme {
case "http":
return "ws", nil
case "https":
return "wss", nil
case "ws", "wss":
return scheme, nil
default:
return "", fmt.Errorf("unexpected scheme: %s", scheme)
}
}