Mercury is a room based chat project which is aiming to help deveplors building a chat service in a fast way. Mercury is an independent service from your app which make you can take more concentration on your app. We are also planning to make Mercury to a distributed chat service for a more scalability.
The Mercury is designed into two part, Rest API server and Websocket server.
API | Method | Description |
---|---|---|
/api/token | GET | Get token of a user for a websocket connection |
/api/room/add | POST | add members into a chat room |
Connect to the server using the token.
ws://<ip>:<port>/ws/connect?token=xxxx&member=xxx
Merucy server receive a json format message. The client should send a json data to the server in the websocket connection.
{
"type": 1,
"rid": "<room id>",
"text" "<message>",
}
{
"type": 2,
"msgid": "<start message id>",
"offset" "<number of message before msgid>",
}
Basic server configuration
config | default value |
---|---|
--server.api.address | 127.0.0.1/32 |
--server.ws.address | 0.0.0.0/0 |
--server.api.port | 6009 |
--server.ws.port | 6010 |
- Mercury only recive a IPv4 remote ip currently.
Logging in Mercury is using the interface provided by go-kit
config | available value |
---|---|
--log.format | json(default) | logfmt |
--log.level | info(default) | warn | error | debug |
You can choose from multiple back end storage to store the data in the Mercury.
MySQL
config | default value |
---|---|
--mysql.host | "" |
--mysql.port | 3306 |
--mysql.user | root |
--mysql.password | "" |
Redis
config | default value |
---|---|
--redis.host | "" |
--redis.port | 6379 |
--reids.password | "" |
--redis.db | 0 |
You can also configure the Mercury through a config file which is using the https://github.com/jinzhu/configor
The YAML, JSON, TOML format of configure file are supported.
The default file path is ./mc.cnf.toml
and can be set by --config.file
command line option.
Here is an example of configure file https://github.com/leeif/mercury/blob/master/config/config_file.go
~$ go get github.com/leeif/mercury
~$ cd $GOPATH/src/github.com/leeif/mercury
~$ dep ensure
Start Mrcury server
~$ go run ./
Test client
// Terminal 1
~$ go run ./test --member=1
// Terminal 2
~$ go run ./test --member=2
Send Message
// Terminal 1
send> Hello World 1
// Termianl 2
send> Hello World 2
Slack : #mushare-dev