domain

package
v0.0.0-...-ef566a4 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2014 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Id       int64
	Name     string
	Public   bool
	Capacity int
	Clients  []*Client
	Messages []*Message
	// contains filtered or unexported fields
}

Chat channel Goroutine safe

func NewChannel

func NewChannel(name string) *Channel

func (*Channel) HasAccess

func (c *Channel) HasAccess(client *Client) bool

HasAccess checks if the client has access to the channel

func (*Channel) Join

func (c *Channel) Join(client *Client) error

Join adds a client to the channel

func (*Channel) Leave

func (c *Channel) Leave(client *Client) error

Leave removes a client from the channel

func (*Channel) Send

func (c *Channel) Send(message *Message)

Send sends a message to every client in the channel

type ChannelRepository

type ChannelRepository interface {
	GetChannels() (map[int64]*Channel, error)
	Store(channel *Channel) error
	FindById(id int64) (*Channel, error)
}

type Client

type Client struct {
	Id          int64
	DisplayName string
	FirstName   string
	LastName    string
	Email       string

	Channel      *Channel
	ClientSender ClientSender
}

Client is a normal user of the chat service

type ClientRepository

type ClientRepository interface {
	Store(client *Client) error
	FindById(id int64) (*Client, error)
}

type ClientSender

type ClientSender interface {
	Send(message *Message)
	ChannelCreated(channel *Channel)
	ChannelJoined(channel *Channel, client *Client)
}

ClientSender is used to send information to the client

type Message

type Message struct {
	Id        int64
	Body      string
	ClientId  int64
	ChannelId int64
	Author    string
	Time      time.Time
}

Message

type MessageRepository

type MessageRepository interface {
	Store(message *Message) error
	FindById(id int64) (*Message, error)
	FindByChannelId(channelId int64, max int) ([]*Message, error)
	FindByClientId(clientId int64, max int) ([]*Message, error)
}

type Server

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

Server Goroutine safe

func NewServer

func NewServer(channels map[int64]*Channel, clients map[int64]*Client) *Server

func (*Server) AddChannel

func (s *Server) AddChannel(channel *Channel)

AddChannel creates a channel in the server

func (*Server) AddClient

func (s *Server) AddClient(client *Client) error

AddClient adds a client to the server

func (*Server) GetChannel

func (s *Server) GetChannel(channelId int64) *Channel

GetChannel returns the channel with channelId

func (*Server) GetChannels

func (s *Server) GetChannels() map[int64]*Channel

GetChannels returns a copy of the channels map

func (*Server) GetClient

func (s *Server) GetClient(clientId int64) *Client

GetClient returns the client with clientId

func (*Server) GetClients

func (s *Server) GetClients() map[int64]*Client

GetClients returns a copy of the clients map

func (*Server) RemoveChannel

func (s *Server) RemoveChannel(channelId int64)

RemoveChannel deletes a channel in the server

func (*Server) RemoveClient

func (s *Server) RemoveClient(clientId int64) error

RemoveClient removes a client from the server

type ServerRepository

type ServerRepository interface {
	Get() *Server
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳