goch

package module
v0.0.0-...-8c28d06 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 4 Imported by: 0

README

goch

Build Status codecov Go Report Card Maintainability

goch is a self-hosted live-chat server written in Go.

It allows you to run a live-chat software on your own infrastructure.

You can create multiple private and public chatrooms where two or more users can be at the same time.

For communication, it uses RESTful endpoints, Websockets, NATS Streaming, and Redis.

Goch is a fork of Gossip, with many added features and fixes.

Getting started

To run goch locally, you need docker, docker-compose and go installed and set on your path. After downloading/cloning the project, run ./up which compiles the binary and runs docker-compose with goch, NATS Streaming, and Redis. If there were no errors, goch should be running on localhost (port 8080).

How it works

In order for the server to run, ADMIN_USERNAME and ADMIN_PASSWORD env variables have to be set. In the repository, they are set to admin and pass respectively, but you should obviously change those for security reasons.

Once the server is running, the following routes are available:

  • POST /admin/channels: Creates a new channel. You have to provide a unique name for a channel (usually an ID), and the response includes channel's secret which will be used for connecting to channel later on. This endpoint should be invoked server-side with provided admin credentials. The response should be saved in order to connect to the channel later on.

  • POST /register: Register a user in a channel. In order to register for the channel, a UID, DisplayName, ChannelSecret, and ChannelName needs to be provided. Optionally user secret needs to be provided, but if not the server will generate and return one.

  • GET /connect: Connects to a chat and returns a WebSocket connection, along with chat history. Channel, UID, and Secret need to be provided. Optionally LastSeq is provided which will return chat history only after LastSeq (UNIX timestamp).

The remaining routes are only used as 'helpers':

  • GET /channels/{name}?secret=$SECRET: Returns list of members in a channel. Channel name has to be provided as URL param and channel secret as a query param.

  • GET /admin/channels: Returns list of all available channels.

  • GET /admin/channels/{name}/user/{uid}: Returns list of unread messages on a chat for a user.

License

goch is licensed under the MIT license. Check the LICENSE file for details.

Author

Emir Ribic

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chat

type Chat struct {
	Name    string           `json:"name"`
	Secret  string           `json:"secret"`
	Members map[string]*User `json:"members"`
}

Chat represents private or channel chat

func DecodeChat

func DecodeChat(b string) (*Chat, error)

DecodeChat tries to decode binary formatted message in b to Message

func NewChannel

func NewChannel(name string, private bool) *Chat

NewChannel creates new channel chat

func (*Chat) Encode

func (c *Chat) Encode() ([]byte, error)

Encode encodes provided chat in binary format

func (*Chat) Join

func (c *Chat) Join(uid, secret string) (*User, error)

Join attempts to join user to chat

func (*Chat) Leave

func (c *Chat) Leave(uid string)

Leave removes user from channel

func (*Chat) ListMembers

func (c *Chat) ListMembers() []*User

ListMembers returns list of members associated to a chat

func (*Chat) Register

func (c *Chat) Register(u *User) (string, error)

Register registers user with a chat and returns secret which should be stored on the client side, and used for subsequent join requests

type Limit

type Limit int

Limit represents limit type

const (
	DisplayNameLimit Limit = iota + 1
	UIDLimit
	SecretLimit
	ChanLimit
	ChanSecretLimit
)

Limit constants

type Message

type Message struct {
	Meta     map[string]string `json:"meta"`
	Time     int64             `json:"time"`
	Seq      uint64            `json:"seq"`
	Text     string            `json:"text"`
	FromUID  string            `json:"from_uid"`
	FromName string            `json:"from_name"`
}

Message represents chat message

func DecodeMsg

func DecodeMsg(b []byte) (*Message, error)

DecodeMsg tries to decode binary formatted message in b to Message

func (*Message) Encode

func (m *Message) Encode() ([]byte, error)

Encode encodes provided chat Message in binary format

type User

type User struct {
	UID         string `json:"uid"`
	DisplayName string `json:"display_name"`
	Email       string `json:"email"`
	Secret      string `json:"secret"`
}

User represents user entity

Directories

Path Synopsis
cmd
internal
broker
Package broker provides chat broker functionality
Package broker provides chat broker functionality
ingest
Package ingest provides functionality for updating per chat read models (recent history)
Package ingest provides functionality for updating per chat read models (recent history)
pkg

Jump to

Keyboard shortcuts

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