提交 13efb93b 编写于 作者: W wuhanqing

UPDATE docs

上级 ab00c24b
## 简介
easyim 是一个简单易用,对二次开发友好,方便部署的即时通讯服务器
easyim 是一个简单易用,二开友好,方便部署的即时通讯服务器。如数据量大、对性能有要求,请自行扩展,并将`sqlite3` 替换为其他数据库
如数据量大、对性能有要求,请将`sqlite3` 替换为其他数据库。
在线文档: [https://imdocs.catmes.com](https://imdocs.catmes.com)
代码源于刘丹冰老师视频:[8小时转职Golang工程师](https://www.bilibili.com/video/BV1gf4y1r79E/) - 即时通讯系统
代码源于刘丹冰老师视频教程[8小时转职Golang工程师](https://www.bilibili.com/video/BV1gf4y1r79E/) - 即时通讯系统
## 开发环境
......@@ -64,7 +64,7 @@ IM数据通讯的长连接,支持数据传输 `json`, `protobuf` 两种格式
| status | MsgStatus | 消息状态(MsgStatus枚举类型:0未发送,1已发送,2已送达,3已读取) |
| content | string | 消息内容,字符串类型 |
请参看 [protobuf/msg.proto](protobuf/msg.proto)文件
请参看 [protobuf/msg.proto](https://github.com/iotames/easyim/blob/master/protobuf/msg.proto)文件
## 在线文档
......
## 简介
easyim 是一个简单易用,对二次开发友好,方便部署的即时通讯服务器。
如数据量大、对性能有要求,请将`sqlite3` 替换为其他数据库。
代码源于刘丹冰老师视频:[8小时转职Golang工程师](https://www.bilibili.com/video/BV1gf4y1r79E/) - 即时通讯系统
## 开发环境
下载并安装Go: https://golang.google.cn/doc/install
设置GO国内代理:
```
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
```
## 快速开始
```
# 加载依赖包
go mod tidy
# 首次运行,添加初始化参数--init,初始化数据库
go run . --init
```
客户端调试:
```
# linux下使用nc命令调试
nc 127.0.0.1 8888
# 使用本项目 `examples` 目录中示例文件调试
go run client.go -ip 127.0.0.1 -port 8888
```
## 配置文件
复制 `env.default` 文件为 `.env`, 并更改新配置文件 `.env` 的配置项,以覆盖 `env.default` 配置文件的默认值
## 通讯数据格式
IM数据通讯的长连接,支持数据传输 `json`, `protobuf` 两种格式。默认为 `protobuf`
如需更改,请在 `.env` 文件,添加配置项 `MSG_FORMAT = "json"`,以覆盖默认值。
数据格式说明:
| 字段名 | 数据类型 | 释义 |
| ------ | --------- | -------- |
| id | string | 消息ID,字符串格式 | |
| seq | uint32 | 时序号,整型。确保消息按正确顺序显示。客户端按用户发送顺序,从小到大填写seq值。 |
| from_user_id | string | 消息发送方ID |
| to_user_id | string | 消息接收方ID |
| chat_type | ChatType | 聊天类型(ChatType枚举类型:0单聊,1群聊) |
| msg_type | MsgType | 消息类型(MsgType枚举类型:0文本,1图片,2语音,3视频) |
| status | MsgStatus | 消息状态(MsgStatus枚举类型:0未发送,1已发送,2已送达,3已读取) |
| content | string | 消息内容,字符串类型 |
请参看 [protobuf/msg.proto](protobuf/msg.proto)文件
## 在线文档
全局安装 `docsify` 文档生成工具:
```
npm i docsify-cli -g
```
- 文档初始化: `docsify init ./docs`
- 本地预览: `docsify serve docs`
\ No newline at end of file
<!-- ![logo](_media/icon.svg) -->
# EasyIM <small>1.0 Beta</small>
> 一款简单的即时通讯服务器
- 纯Go语言实现,Linux, Win, IOS 全平台支持
- 默认 sqlite3 本地存储,无需新建数据库
- 支持常规 TCP 和 WebSocket 长连接
- 支持 json 和 protobuf 数据格式
[GitHub](https://github.com/iotames/easyim/)
[Get Started](#简介)
\ No newline at end of file
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<title>EasyIM在线文档</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
......@@ -12,11 +12,22 @@
<div id="app"></div>
<script>
window.$docsify = {
name: '',
repo: ''
coverpage: true,
coverpage: 'coverpage.md',
onlyCover: false,
maxLevel: 3,
name: 'EasyIM',
repo: 'https://github.com/iotames/easyim/',
homepage: 'https://raw.githubusercontent.com/iotames/easyim/master/README.md',
search: {
maxAge: 86400000, // 过期时间,一天,单位毫秒
placeholder: '搜索',
noData: '找不到搜索数据!',
},
}
</script>
<!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
</body>
</html>
......@@ -11,7 +11,6 @@ import (
// Handler 当前链接的业务
func Handler(s *Server, conn net.Conn) {
u := user.NewUser(conn, s)
u.SetOnConnectStart(func(u user.User) {
fmt.Println("TCP连接建立成功:", conn.RemoteAddr().String())
......
......@@ -16,12 +16,15 @@ func MainHandler(u contract.IUser) error {
if err != nil {
return err
}
// 数据过滤
lendata := len(data)
if lendata < 10 {
err = fmt.Errorf("req data too small")
logger.Debug("---handler.MainHandler--error:", err)
return err
}
dp := model.GetDataPack()
if u.IsHttp(data) && u.MsgCount() == 1 {
// HTTP API 接口业务处理。不支持HTTP 的 Keep-Alive
......@@ -40,7 +43,8 @@ func MainHandler(u contract.IUser) error {
// HTTP 一次请求响应后,立即关闭连接。不支持HTTP 的 Keep-Alive
return u.Close()
}
logger.Debug("---------TCP------u.MsgCount=", u.MsgCount())
logger.Debug("---TCP---ReceivedMessage--SUCCESS-----u.MsgCount=", u.MsgCount())
msg := model.Msg{}
err = dp.Unpack(data, &msg)
......@@ -48,6 +52,8 @@ func MainHandler(u contract.IUser) error {
return fmt.Errorf("unpack msg fail:%v", err)
}
logger.Debug("-----ReceivedMsg(%v)--msg.ChatType(%d)--", msg.String(), msg.ChatType)
// TODO 用户身份鉴权
if msg.ChatType == model.Msg_SINGLE {
// 单聊。发送给TO_USER
msg.Content += "--Msg_SINGLE--Response--"
......
......@@ -9,6 +9,6 @@ import (
func HttpHandler(req *model.Request) error {
hreq := req.GetHttpRequest()
body := req.GetHttpBody()
fmt.Printf("\n--method(%s)--proto(%s)--Header(%+v)--Body(%s)-\n", hreq.Method, hreq.Proto, hreq.Header, string(body))
fmt.Printf("\n--method(%s)--proto(%s)--Path(%+v)--Body(%s)-\n", hreq.Method, hreq.Proto, hreq.URL, string(body))
return req.ResponseJson(ResponseOk("hello response Json From struct")) //
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册