mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
refactor: websockets into 'connect' module, rename & adjust generally
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user