Documentation ¶
Overview ¶
Package server delivers all the functionallity to create a chat server. It supports extensions for multiple transports. See transport.go for more information
Index ¶
- type AuthRegistry
- type Config
- type ContactStore
- type Control
- func (c Control) AddContact(user string, contactId string) bool
- func (c Control) AddToGroup(groupId string, userId string) bool
- func (c *Control) CreateGroup() string
- func (c *Control) DeleteGroup(groupId string) bool
- func (c Control) ListContacts(user string) ([]string, bool)
- func (c Control) ListGroups(userId string) *[]string
- func (c Control) RemoveContact(user string, contactId string) bool
- func (c Control) RemoveFromGroup(groupId string, userId string) bool
- func (c Control) SearchContact(user string, contactName string) string
- type FileStore
- type Group
- type History
- type Messanger
- type OutputStore
- type Server
- type Transport
- type UserHandler
- type WebSocketServer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthRegistry ¶
type AuthRegistry struct {
// contains filtered or unexported fields
}
Stores authenticated users in memory
func NewAuthRegistry ¶
func NewAuthRegistry() *AuthRegistry
func (*AuthRegistry) Authenticate ¶
func (a *AuthRegistry) Authenticate(userId string, pass string) bool
Authenticates authenticates the user id with it's password
func (*AuthRegistry) Register ¶
func (a *AuthRegistry) Register(username string, pass string) (string, bool)
Register generates server domain user id which for now is current ts in nanoseconds
func (*AuthRegistry) SearchContact ¶
func (a *AuthRegistry) SearchContact(username string) string
SearchContact searches globally for contact with param username
type Config ¶
type ContactStore ¶
type ContactStore struct {
// contains filtered or unexported fields
}
Stores contact lists for users
func NewContactStore ¶
func NewContactStore() *ContactStore
func (*ContactStore) AddContact ¶
func (c *ContactStore) AddContact(userId string, contactId string) bool
AddContact adds contact in user's contact list
func (*ContactStore) ListContacts ¶
func (c *ContactStore) ListContacts(userId string) ([]string, bool)
ListContacts returns user's contact list for userId
func (*ContactStore) RemoveContact ¶
func (c *ContactStore) RemoveContact(userId string, contactId string) bool
RemoveContact removes contact from user's contact list
type Control ¶
type Control struct {
// contains filtered or unexported fields
}
Main facility which handles all the control protocol messages
func NewControl ¶
func NewControl(input chan *common.Message, outputStore *OutputStore, contactStore *ContactStore, authRegistry *AuthRegistry) *Control
func (Control) AddContact ¶
AddContact handles protocol "add_contact"
func (Control) AddToGroup ¶
AddToGroup handles protocol "add_to_group"
func (*Control) CreateGroup ¶
CreateGroup handles protocol "create_group"
func (*Control) DeleteGroup ¶
DeleteGroup handles protocol "delete_group"
func (Control) ListContacts ¶
ListContacts handles protocol "list_contacts" Returns array with contact ids
func (Control) ListGroups ¶
ListGroups handles protocol "list_groups"
func (Control) RemoveContact ¶
RemoveContact handles protocol "remove_contact"
func (Control) RemoveFromGroup ¶
RemoveToGroup handles protocol "remove_from_group"
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
Stores the files locally and expose http interfaces from where you can download the files by file token
func NewFileStore ¶
func (FileStore) AddTextFile ¶
AddTextFile stores the stores the file in root folder and generates access uri
func (FileStore) RemoveFile ¶
RemoveFile removes the file for this uri
type Group ¶
Aggregate output. When a message is received in the Out channel it will send it to all outputs in the group. Like a multicast channel
func (*Group) RemoveOutput ¶
RemoveOutput removes output from the aggregate
type History ¶
type History struct {
// contains filtered or unexported fields
}
Stores message history
func NewHistory ¶
func NewHistory(input chan *common.Message, outputStore *OutputStore) *History
func (History) AddMessage ¶
AddMessage adds in the history
type Messanger ¶
type Messanger struct {
// contains filtered or unexported fields
}
Handler for all messages/files communication between the clients.
func NewMessanger ¶
func NewMessanger(input chan *common.Message, history *History, outputStore *OutputStore, fileStore *FileStore) *Messanger
NewMessenger creates a new messagener object which handlers messages through input channel.
type OutputStore ¶
type OutputStore struct {
// contains filtered or unexported fields
}
Store for all authenticated outputs. Main facility to send messages to remote users
func (*OutputStore) AddOutput ¶
func (store *OutputStore) AddOutput(id string, output chan<- *common.Message) error
AddOutput adds user output in the store by id
func (OutputStore) GetOutput ¶
func (store OutputStore) GetOutput(id string) chan<- *common.Message
GetOutput returns a user output from the store by id
func (*OutputStore) RemoveOutput ¶
func (store *OutputStore) RemoveOutput(id string) error
RemoveOutput removes user output from the store by id
func (OutputStore) Send ¶
func (store OutputStore) Send(msg *common.Message)
Send sends a message to user's output
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Main server type
func (*Server) AddTransport ¶
AddTransport adds transport which later will listen on host
func (*Server) RemoveTransport ¶
RemoveTransport removes the transport for the host
func (*Server) Start ¶
Start starts each transport in own gorouting. Blocks until done channel is not closed
func (*Server) StartAsync ¶
StartAsync is same as Start by runs in async mode
Example ¶
s := New(getConfig()) wss := NewWebSocket(getConfig()) s.AddTransport(":9999", &wss) done, err := s.StartAsync() if err != nil { log.Println(err) return } go func() { time.Sleep(time.Second * 3) close(done) }() <-done
Output:
type Transport ¶
type Transport interface { OnUserConnected(chan<- *common.User) OnUserDisconnected(chan<- *common.User) Start(host string, done <-chan interface{}) }
Defines the interface for the transport implementations
type UserHandler ¶
type WebSocketServer ¶
type WebSocketServer struct {
// contains filtered or unexported fields
}
Transport implementation with websocket protocol
func NewWebSocket ¶
func NewWebSocket(config *Config) WebSocketServer
func (*WebSocketServer) OnUserConnected ¶
func (wss *WebSocketServer) OnUserConnected(handler chan<- *common.User)
func (*WebSocketServer) OnUserDisconnected ¶
func (wss *WebSocketServer) OnUserDisconnected(handler chan<- *common.User)
func (*WebSocketServer) ServeHTTP ¶
func (wss *WebSocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*WebSocketServer) Start ¶
func (wss *WebSocketServer) Start(host string, done <-chan interface{})