magical

package module
v0.0.0-...-1f81fe3 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2025 License: MIT Imports: 13 Imported by: 0

README

logo "The protocol engine, that made with MAGIC!"

Magical - is a Go library, that simplifies process of protocol development. Every request that made to your Magical-powered protocol - is an event!

Documentation

Index

Constants

View Source
const (
	MagicalMessage websocket.MessageType = iota + 3
)

Variables

This section is empty.

Functions

func EventPack

func EventPack(input any) ([]byte, error)

func EventUnpack

func EventUnpack(input []byte, output any) error

Types

type Client

type Client struct {
	sync.Mutex

	Protocol string
	Host     string
	Port     int

	Connection *Connection
	// contains filtered or unexported fields
}

func NewClient

func NewClient(protocol string, host string, port int) *Client

func (*Client) Handle

func (client *Client) Handle()

func (*Client) Poll

func (client *Client) Poll() (EventType, []byte)

func (*Client) Start

func (client *Client) Start() error

type Connection

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

func NewConnection

func NewConnection(subprotocol string) *Connection

func (*Connection) Accept

func (conn *Connection) Accept(writer http.ResponseWriter, request *http.Request) error

func (*Connection) Close

func (conn *Connection) Close()

func (*Connection) Connect

func (conn *Connection) Connect(address string) error

func (*Connection) EnableEncryption

func (conn *Connection) EnableEncryption(encryption Encryption)

func (*Connection) Receive

func (conn *Connection) Receive() (EventType, []byte, error)

func (*Connection) Send

func (conn *Connection) Send(eventType EventType, message []byte) error

func (*Connection) SetSharedKey

func (conn *Connection) SetSharedKey(key []byte)

type ConnectionError

type ConnectionError struct {
	Stage  string
	Reason string
}

func (ConnectionError) Error

func (err ConnectionError) Error() string

type Encryption

type Encryption interface {
	Init() error

	GetPublicKey() ([]byte, error)

	Encrypt(message []byte, targetKey []byte) ([]byte, error)
	Decrypt(message []byte) ([]byte, error)
}

type Event

type Event interface{}

type EventData

type EventData struct {
	Type EventType
	Data []byte
}

type EventError

type EventError struct {
	Message   string `json:"message"`
	Timestamp string `json:"timestamp"`
}

type EventHandler

type EventHandler func(*Connection, []byte) Event

type EventType

type EventType byte
const (
	EventTypeError EventType = 0
)

type HttpRouteHandler

type HttpRouteHandler func(http.ResponseWriter, *http.Request)

type HttpServer

type HttpServer struct {
	Address string
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer() *HttpServer

func (*HttpServer) Bind

func (server *HttpServer) Bind(pattern string, handler HttpRouteHandler)

func (*HttpServer) Close

func (server *HttpServer) Close()

func (*HttpServer) Listen

func (server *HttpServer) Listen() error

func (*HttpServer) ServeHTTP

func (server *HttpServer) ServeHTTP(writer http.ResponseWriter, request *http.Request)

type HttpServerError

type HttpServerError struct {
	Stage  string
	Reason string
}

func (HttpServerError) Error

func (err HttpServerError) Error() string

type Protocol

type Protocol struct {
	Host string
	Port int
	Name string
	// contains filtered or unexported fields
}

func NewProtocol

func NewProtocol(name string) *Protocol

func (*Protocol) BindEventHandler

func (proto *Protocol) BindEventHandler(eventType EventType, eventHandler EventHandler)

func (*Protocol) Close

func (proto *Protocol) Close()

func (*Protocol) Start

func (proto *Protocol) Start() error

func (*Protocol) WebSocketHandler

func (proto *Protocol) WebSocketHandler(writer http.ResponseWriter, request *http.Request)

Jump to

Keyboard shortcuts

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