gordian

package module
v0.0.0-...-c41c5b1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2017 License: MIT Imports: 5 Imported by: 2

README

Gordian is a small framework for making multiclient websocket apps in go.

Documentation

Overview

The gordian package provides a simple framework for building multiclient websocket applications.

Index

Constants

View Source
const (
	Connect = iota
	Register
	Establish
	Abort
	Close
)

Control types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Id      ClientId        // Id is a unique identifier.
	Ctrl    int             // Ctrl is the current control type.
	Conn    *websocket.Conn // Conn is the connection info provided by the websocket package.
	Request *http.Request   // Request is the original http request
	// contains filtered or unexported fields
}

Client stores state and control information for a client.

type ClientId

type ClientId interface{}

ClientId is a user-defined client identifier, which can be of any hashable type.

type Gordian

type Gordian struct {
	Control chan *Client // Control is used to pass client control information within Gordian.
	InBox   chan Message // InBox passes incoming messages from clients to Gordian.
	OutBox  chan Message // OutBox passes outgoing messages from Gordian to clients.
	// contains filtered or unexported fields
}

Gordian processes and distributes messages and manages clients.

func New

func New(bufSize int) *Gordian

New constructs an initialized Gordian instance.

func (*Gordian) Run

func (g *Gordian) Run()

Run starts Gordian's event loop.

func (*Gordian) ServeHTTP

func (g *Gordian) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles a websocket connection

type Message

type Message struct {
	From ClientId    // From is the originating client.
	To   ClientId    // To is the destination client.
	Type string      // Type is the type of message.
	Data MessageData // Data is the message payload.
}

Message is the internal message format

func (*Message) Unmarshal

func (m *Message) Unmarshal(data interface{}) error

Unmarshal decodes json data in an incoming message

type MessageData

type MessageData interface{}

MessageData is a user-defined message payload.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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