wsm

package
v0.1.0-alpha.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Disconnected = "Disconnected"
	Connecting   = "Connecting"
	Connected    = "Connected"
	Reconnecting = "Reconnecting"
	Closed       = "Closed"
)

Variables

This section is empty.

Functions

func ConvertMapToString

func ConvertMapToString(v any) (string, error)

func ConvertSliceToString

func ConvertSliceToString(elem []string) string

func ConvertValueIntoType

func ConvertValueIntoType[T any](v interface{}, checkPointer bool) (T, bool)

ConvertValueIntoType attempts to convert an interface{} to a value of type T.

Parameters: - v: the input value of any type. - checkPointer: if true, allows de-referencing if v is a *T.

func ExtractAnyMap

func ExtractAnyMap(m map[string]interface{}, key string, coerce bool) (map[string]interface{}, bool, error)

func ExtractAnySlice

func ExtractAnySlice(m map[string]interface{}, key string, coerce bool) ([]interface{}, bool, error)

func ExtractInt64Map

func ExtractInt64Map(m map[string]interface{}, key string, coerce bool) (map[string]int64, bool, error)

func ExtractInt64Slice

func ExtractInt64Slice(m map[string]interface{}, key string, coerce bool) ([]int64, bool, error)

func ExtractMap

func ExtractMap[T any](m map[string]interface{}, key string, coerce bool, conv func(interface{}) (T, bool)) (map[string]T, bool, error)

func ExtractSlice

func ExtractSlice[T any](m map[string]interface{}, key string, coerce bool, conv func(interface{}) (T, bool)) ([]T, bool, error)

func ExtractStringMap

func ExtractStringMap(m map[string]interface{}, key string, coerce bool) (map[string]string, bool, error)

func ExtractStringSlice

func ExtractStringSlice(m map[string]interface{}, key string, coerce bool) ([]string, bool, error)

func ExtractUint64Map

func ExtractUint64Map(m map[string]interface{}, key string, coerce bool) (map[string]uint64, bool, error)

func ExtractUint64Slice

func ExtractUint64Slice(m map[string]interface{}, key string, coerce bool) ([]uint64, bool, error)

func ExtractValue

func ExtractValue[T any](m map[string]interface{}, key string) (T, bool, error)

func SplitMessageIntoMap

func SplitMessageIntoMap(s string) (map[string]interface{}, error)

Types

type ConnectionManager

type ConnectionManager interface {
	Close() error
	Get() *WSConnection
	Save(wsConnection *WSConnection)
}

type DefaultConnectionManagerImpl

type DefaultConnectionManagerImpl struct {
	// contains filtered or unexported fields
}

func (*DefaultConnectionManagerImpl) Close

func (*DefaultConnectionManagerImpl) Get

func (*DefaultConnectionManagerImpl) Save

type LegacyCommand

type LegacyCommand struct {
	Name  string
	Alias string
	Short string
}

type Message

type Message interface {
	Type() string
	String() string
	SafeString() (string, error)
}

type MissingFieldError

type MissingFieldError struct {
	GoField    string
	GoType     string
	JSONField  string
	StructName string
}

func NewMissingFieldError

func NewMissingFieldError(goField, goType, jsonField, structName string) MissingFieldError

func (MissingFieldError) Error

func (e MissingFieldError) Error() string

type NewMessageFromMap

type NewMessageFromMap map[string]NewMessageFromMapFunc

func (NewMessageFromMap) New

func (r NewMessageFromMap) New(typeName string, m map[string]interface{}) (Message, error)

type NewMessageFromMapFunc

type NewMessageFromMapFunc func(m map[string]interface{}) (Message, error)

func WrapNewMessageFromMapFunc

func WrapNewMessageFromMapFunc[T any](fn func(map[string]interface{}) (*T, error)) NewMessageFromMapFunc

type WSConnection

type WSConnection struct {
	Conn     *websocket.Conn
	Mu       sync.RWMutex
	MuStatus sync.RWMutex

	Header http.Header
	Data   map[string]interface{}
	Meta   map[string]interface{}

	EnableAutoReconnect  bool
	MaxReconnectAttempts int

	StatusHandler  WSConnectionStatusHandler
	MessageHandler WSConnectionMessageHandler
	// contains filtered or unexported fields
}

func NewWSConnection

func NewWSConnection(
	configRepo repository.ConfigRepository,
	tokenRepo repository.TokenRepository,
	options ...WSConnectionOption,
) (*WSConnection, error)

func (*WSConnection) Close

func (c *WSConnection) Close(code int, reason string) error

func (*WSConnection) DefaultCloseHandler

func (c *WSConnection) DefaultCloseHandler(code int, reason string) error

func (*WSConnection) DefaultPongHandler

func (c *WSConnection) DefaultPongHandler(text string) error

func (*WSConnection) Dial

func (c *WSConnection) Dial(url string, headers http.Header) (*websocket.Conn, error)

func (*WSConnection) GetData

func (c *WSConnection) GetData(key string) interface{}

func (*WSConnection) GetStatus

func (c *WSConnection) GetStatus() string

func (*WSConnection) Lock

func (c *WSConnection) Lock(location string)

func (*WSConnection) SetStatus

func (c *WSConnection) SetStatus(status string)

func (*WSConnection) Unlock

func (c *WSConnection) Unlock(location string)

type WSConnectionMessageHandler

type WSConnectionMessageHandler func(msg []byte)

type WSConnectionOption

type WSConnectionOption func(wsConn *WSConnection) error

func WithEnableAutoReconnect

func WithEnableAutoReconnect() WSConnectionOption

func WithMaxReconnectAttempts

func WithMaxReconnectAttempts(maxReconnectAttempts int) WSConnectionOption

func WithMessageHandler

func WithMessageHandler(handler WSConnectionMessageHandler) WSConnectionOption

func WithScheme

func WithScheme(scheme string) WSConnectionOption

func WithStatusHandler

func WithStatusHandler(handler WSConnectionStatusHandler) WSConnectionOption

func WithToken

func WithToken(token string) WSConnectionOption

type WSConnectionStatusHandler

type WSConnectionStatusHandler func(status string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL