openws

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 7 Imported by: 0

README

OpenWS-go

Golang implementation of the OpenWS protocol.

Documentation

Index

Constants

View Source
const (
	CodeParseError         = -32700
	CodeInvalidRequest     = -32600
	CodeMethodNotFound     = -32601
	CodeInvalidParams      = -32602
	CodeInternalError      = -32603
	CodeUnimplementedError = -32604
)
View Source
const JSONRPCVer = "2.0"

Variables

This section is empty.

Functions

func BroadcastEvent added in v0.1.2

func BroadcastEvent(
	ctx context.Context,
	eventName string,
	data any,
	conns ...*websocket.Conn,
) (<-chan SendResult, error)

func EmitEvent

func EmitEvent(
	ctx context.Context,
	eventName string,
	data any,
	conn *websocket.Conn,
) error

func Register

func Register[Params any, Result any](s *Server, method string, fn func(context.Context, *Params) (Result, error))

Types

type Error

type Error struct {
	Code    int32  `json:"code"`
	Message string `json:"message"`
	Details any    `json:"details,omitempty"`
}

func (*Error) Error

func (e *Error) Error() string

type Event

type Event struct {
	Event string `json:"event"`
	Data  any    `json:"data,omitempty"`
}

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id,omitempty"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
}

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      json.RawMessage `json:"id"`
	Result  any             `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

type SendResult added in v0.1.2

type SendResult struct {
	Conn *websocket.Conn
	Err  error
}

type Server

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

func NewServer

func NewServer() *Server

func (Server) ServeConn

func (s Server) ServeConn(ctx context.Context, conn *websocket.Conn) error

Jump to

Keyboard shortcuts

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