{"id":37118160,"url":"https://github.com/iotames/easyim","last_synced_at":"2026-01-14T13:48:37.962Z","repository":{"id":102096840,"uuid":"602875773","full_name":"iotames/easyim","owner":"iotames","description":"简单易用的即时通讯系统","archived":false,"fork":false,"pushed_at":"2023-09-28T07:55:29.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-17T01:02:15.580Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iotames.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-17T05:56:42.000Z","updated_at":"2023-04-07T01:52:25.000Z","dependencies_parsed_at":"2024-06-21T17:35:21.750Z","dependency_job_id":"0e9dbe69-d8af-4d7e-8807-7f979951a4fc","html_url":"https://github.com/iotames/easyim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/iotames/easyim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iotames","download_url":"https://codeload.github.com/iotames/easyim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iotames%2Feasyim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28422346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T13:30:50.153Z","status":"ssl_error","status_checked_at":"2026-01-14T13:29:08.907Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T13:48:37.189Z","updated_at":"2026-01-14T13:48:37.951Z","avatar_url":"https://github.com/iotames.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 简介\n\neasyim 是一个简单易用，二开友好，方便部署的即时通讯服务器。如数据量大、对性能有要求，请自行扩展，并将`sqlite3` 替换为其他数据库。\n\n在线文档: [https://imdocs.catmes.com](https://imdocs.catmes.com)\n\n代码源于刘丹冰老师视频教程：[8小时转职Golang工程师](https://www.bilibili.com/video/BV1gf4y1r79E/) - 即时通讯系统\n\n\n## 客户端\n\n- Flutter [https://github.com/dou23/easy_im](https://github.com/dou23/easy_im)\n\n\n## 开发环境\n\n下载并安装Go: https://golang.google.cn/doc/install\n\n```\n# 开启 module 功能\ngo env -w GO111MODULE=on\n# 设置GO国内代理. 若执行 go mod tidy 命令提示模块下载失败. 请更换模块代理再重试 go env -w GOPROXY=https://goproxy.cn,direct\ngo env -w GOPROXY=https://goproxy.io,direct\n```\n\nWindows环境下，如发现 `cgo` 报错，可能为 `sqlite3` 组件编译错误。请安装C编译器 [TDM-GCC](https://jmeubank.github.io/tdm-gcc/download/) 或 [Mingw-w64](https://github.com/niXman/mingw-builds-binaries/releases/latest)\n\n\n## 快速开始\n\n```\n# 加载依赖包\ngo mod tidy\n\n# 首次运行，添加初始化参数--init，初始化数据库\ngo run . --init\n\n# 正常开发时调试运行\ngo run .\n\n# 编译为二进制文件. 然后直接运行./easyim(easyim.exe)\ngo build .\n```\n\n客户端调试:\n\n```\n# linux下使用nc命令调试\nnc 127.0.0.1 8888\n\n# 使用本项目 `examples` 目录中示例文件调试\ngo run client.go -ip 127.0.0.1 -port 8888\n```\n\n\n## 配置文件\n\n复制 `env.default` 文件为 `.env`, 并更改新配置文件 `.env` 的配置项，以覆盖 `env.default` 配置文件的默认值\n\n\n## 通讯数据格式\n\nIM数据通讯的长连接，支持数据传输 `json`, `protobuf` 两种格式。默认为 `protobuf`。\n\n如需更改，请在 `.env` 文件，添加配置项 `MSG_FORMAT = \"json\"`，以覆盖默认值。\n\n数据格式说明:\n\n| 字段名 | 数据类型 | 释义   |\n| ------ | --------- | -------- |\n| id | string |     消息ID，字符串格式     |         |\n| seq   | uint32     | 时序号，整型。确保消息按正确顺序显示。客户端按用户发送顺序，从小到大填写seq值。  |\n| from_user_id   | string     | 消息发送方ID |\n| to_user_id   | string     | 消息接收方ID |\n| chat_type   | ChatType     | 聊天类型(ChatType枚举类型:0单聊,1群聊) |\n| msg_type   | MsgType     | 消息类型(MsgType枚举类型:0文本,1图片,2语音,3视频,4事件,5系统通知) |\n| status   | MsgStatus     | 消息状态(MsgStatus枚举类型:0未发送,1已发送,2已送达,3已读取) |\n| content   | string     | 消息内容，字符串类型 |\n| access_token | string | 鉴权令牌，字符串类型。用户登录成功后获取|\n\n请参看 [protobuf/msg.proto](https://github.com/iotames/easyim/blob/master/protobuf/msg.proto)文件\n\n\n```\n# 下载 protoc 命令工具，用来生成特定语言的 protobuf 数据处理文件\n# https://github.com/protocolbuffers/protobuf/releases\n# 安装 protoc-gen-go 插件，解析protobuf协议数据为Go语言的数据处理文件\n# go install google.golang.org/protobuf/cmd/protoc-gen-go@latest\n# 根据msg.proto协议文件，在model目录，生成Go语言的protobuf数据处理文件\nprotoc --go_out=model protobuf/msg.proto\n```\n\n### 事件消息\n\n当 `msg_type=4` 时，代表当前通讯数据为一条`事件消息`。 `事件ID` 定义如下表所示:\n\n| 事件ID | 释义  |\n| ----- | ----- |\n|  KEEP_ALIVE  | 心跳事件 |\n|  FRIEND_INVITE  | 好友邀请 |\n|  FRIEND_AGREE  | 同意好友邀请 |\n\n`事件ID` 为字符串，代表事件类型(如心跳事件, 好友邀请)，事件消息的 `content` 字段内容为json字符串。\n\n服务端给客户端发送的json数据，为统一格式: `{\"code\":200,\"msg\":\"SUCCESS\",\"data\":{\"key\":\"KEEP_ALIVE\"}}`\n\n| 字段|数据类型 |释义 |\n|---   | --- | ---   |\n| code  | 整数 |状态码|\n| msg  |字符串 |提示信息|\n| data |json对象| 消息主体|\n| key  | 字符串 | 事件ID|\n\n具体事件消息示例:\n\n| 事件              | from_user_id  | to_user_id    | content |\n| -----            | -----          | -----         | -----       |\n| 客户端上报心跳    | 客户端user_id  |               |  {\"key\":\"KEEP_ALIVE\"} |\n| 服务端响应心跳    |               | 客户端user_id  |  {\"code\":200,\"msg\":\"SUCCESS\",\"data\":{\"key\":\"KEEP_ALIVE\"}} |\n| 客户端发送好友邀请 |                |  对方user_id  | {\"key\":\"FRIEND_INVITE\"} |\n| 客户端收到好友邀请 | 邀请方user_id  |               | {\"code\":200,\"msg\":\"SUCCESS\",\"data\":{\"key\":\"FRIEND_INVITE\"}} |\n| 客户端同意好友邀请 | 被邀请user_id  | 邀请方user_id  | {\"key\":\"FRIEND_AGREE\"} |\n\n### 心跳消息\n\n`心跳消息` 是一种特殊的 `事件消息`， 用于客户端向服务端发送周期性消息。因为服务端长期未收到消息，会主动断开连接。\n\n- 发送原因： 用户一直未主动发消息，又要保持与服务端的长连接不断开，才能持续接收在线消息。\n- 发送频率： 服务端有长期未收到消息，主动断开连接的 `等待时间` , 客户端`心跳发送周期`，稍小于该时间。\n- 首次发送： 建立TCP连接后，客户端发送的首条消息必须为 `心跳消息`，告诉服务端用户已上线。\n\n`心跳消息` 发送方式，请参看 `事件消息` 介绍。\n\n\n## 在线调试\n\n1. 在 `.env` 文件中，设置 `MSG_FORMAT = \"json\"`\n2. 进入 websocket 在线调试网页: [https://websocketking.com/](https://websocketking.com/) 或 [http://www.websocket-test.com/](http://www.websocket-test.com/)\n3. 输入连接地址. 如: `ws://127.0.0.1:8888`. 然后点击连接\n4. 连接成功后，在对话框中，发送符合规范的 json 格式数据，查看服务器数据响应。\n5. 如发送数据不符合规范，服务器会断开连接。\n\njson格式数据示例:\n\n```\n{\"id\":\"1630392697653039104\",\"seq\":0,\"from_user_id\":\"1630381388895096832\",\"to_user_id\":\"1630381388895666666\",\"chat_type\":0,\"msg_type\":0,\"status\":1,\"content\":\"hello word.can you received ?\",\"access_token\":\"aa.bbb.cc\"}\n```\n\n\n## 在线文档\n\n### docsify 文档工具\n\n```\n# 全局安装 docsify 文档生成工具\nnpm i docsify-cli -g\n# 文档初始化\ndocsify init ./docs\n# 本地预览. 默认地址: http://localhost:3000\ndocsify serve docs\n```\n\n### apidoc 文档工具\n\n```\n# 全局安装 apidoc 文档工具，可以根据代码注释，生成API文档\nnpm install -g apidoc\n# 扫描 server/handler 目录中的代码注释，在 docs/apidoc 目录生成API文档\napidoc -i server/handler -o docs/apidoc\n# 配置文件 apidoc.json\n# 默认地址: http://localhost:3000/apidoc/index.html\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiotames%2Feasyim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiotames%2Feasyim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiotames%2Feasyim/lists"}