hub

package
v0.0.0-...-5d8465c Latest Latest
Warning

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

Go to latest
Published: May 23, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package hub provides messages' routing and processing logic.

Index

Constants

This section is empty.

Variables

View Source
var ErrNickCollision = errors.New("Nickname is occupied! Please choose another one...")

ErrNickCollision is returned by Hub.RegisterClient() if connecting client wants to have the nickname that is already occupied.

Functions

func DefaultNameChecker

func DefaultNameChecker(name string) (string, error)

DefaultNameChecker is a sample NameChecker which strips out HTML and leading/trailing spaces.

Types

type ClientAcceptor

type ClientAcceptor interface {
	// RegisterClient adds the client with given nickname
	// to the hub and starts processing its messages.
	RegisterClient(client.Client, string) error
}

ClientAcceptor registers clients and routes messages between them.

type Hub

type Hub interface {
	ClientAcceptor
	// Run starts the hub's messaging pump.
	Run()
}

Hub routes messages between clients and controls the clients connected to it.

func NewHub

func NewHub(checker NameChecker, sanitizer Sanitizer, l logger.Logger) Hub

NewHub initiates and returns the default Hub. Execute hub.Run() to run the processing pumps.

type NameChecker

type NameChecker func(string) (string, error)

NameChecker validates the users' nicknames. Should return transformed nickname and error if client should be refused to join.

type Sanitizer

type Sanitizer func(string) string

Sanitizer transforms the message's text.

Jump to

Keyboard shortcuts

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