{"id":15320382,"url":"https://github.com/cocainecong/gin-chat-demo","last_synced_at":"2025-04-14T12:50:34.205Z","repository":{"id":161628325,"uuid":"435444991","full_name":"CocaineCong/gin-chat-demo","owner":"CocaineCong","description":"gin+websocket+mongodb实现 IM 即时聊天系统，基于WS连接的即时聊天，支持单聊，在线回复以及历史记录查询","archived":false,"fork":false,"pushed_at":"2022-06-20T11:43:51.000Z","size":36,"stargazers_count":133,"open_issues_count":0,"forks_count":40,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T01:53:39.444Z","etag":null,"topics":["gin","go","im","mongodb","redis","tcp","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CocaineCong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-12-06T10:01:30.000Z","updated_at":"2025-03-27T02:22:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"80304944-39cc-4419-a89b-2e20c24ab2df","html_url":"https://github.com/CocaineCong/gin-chat-demo","commit_stats":{"total_commits":18,"total_committers":3,"mean_commits":6.0,"dds":"0.11111111111111116","last_synced_commit":"dc84cae23a58ab2daffad4419e4c583aa9d22b01"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CocaineCong%2Fgin-chat-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CocaineCong%2Fgin-chat-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CocaineCong%2Fgin-chat-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CocaineCong%2Fgin-chat-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CocaineCong","download_url":"https://codeload.github.com/CocaineCong/gin-chat-demo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248884504,"owners_count":21177426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["gin","go","im","mongodb","redis","tcp","websocket"],"created_at":"2024-10-01T09:08:21.194Z","updated_at":"2025-04-14T12:50:34.196Z","avatar_url":"https://github.com/CocaineCong.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gin-chat-demo\ngin+websocket+mongodb实现 IM 即时聊天系统\n\n\u003e \n\u003e 这个项目是基于WebSocket + MongoDB + MySQL + Redis。\n\u003e 业务逻辑很简单，只是两人的聊天。\n\n- `MySQL` 用来存储用户基本信息\n- `MongoDB` 用来存放用户聊天信息\n- `Redis` 用来存储处理过期信息\n\n# 项目教程\nB站：https://www.bilibili.com/video/BV1BP4y1H7gV\n\n博客：https://blog.csdn.net/weixin_45304503/article/details/121787022\n\n\n# 项目结构\n\n```\ngin-chat-demo/\n├── cache\n├── conf\n├── e\n├── model\n├── router\n└── service\n```\n\n- cache : 放置redis配置\n- conf : 放置配置文件 \n- model : 数据库模型\n- pkg : 防止一些错误码\n- router ： 路由模块\n- service ：服务模块\n\n# 项目功能\n\n- 两人通信\n- 在线、不在线应答\n- 查看历史聊天记录\n\n# 配置文件\n- conf/config.ini\n\n```ini\n#debug开发模式,release生产模式\n[service]\nAppMode = debug\nHttpPort = :3000 \n# 运行端口号 3000端口\n\n[mysql]\nDb = mysql\nDbHost = \"\" \n# mysql的ip地址\nDbPort = \"\"\n# mysql的端口号,默认3306\nDbUser = \"\"\n# mysql user\nDbPassWord = \"\"\n# mysql password\nDbName = \"\"\n# 数据库名字\n\n[redis]\nRedisDb = \"\"\n# redis 名字\nRedisAddr = \"\"\n# redis 地址\nRedisPw = \"\"\n# redis 密码\nRedisDbName = \"\"\n# redis 数据库名\n\n[MongoDB]\nMongoDBName =  \"\"\nMongoDBAddr = \"\"\nMongoDBPwd = \"\"\nMongoDBPort = \"\"\n```\n\n# 项目运行\n\n- 下载依赖\n\n```go\ngo mod tidy\n```\n\n- 执行\n\n```go\ngo run main.go\n```\n\n# 演示\n- 测试http连接\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/7ddfc3253d3d4df48460eea2772ede60.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP55Sf5Yeh5LiA,size_20,color_FFFFFF,t_70,g_se,x_16)\n- 进行ws连接，连接服务器\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/cb69e11c10d341abb4a421d304c3c6e1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP55Sf5Yeh5LiA,size_20,color_FFFFFF,t_70,g_se,x_16)\n\n\n- 当id=1上线，但是id=2没上线的时候发送消息\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/b52f92d1437b4d4891c47c2187ffdd65.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP55Sf5Yeh5LiA,size_20,color_FFFFFF,t_70,g_se,x_16)\n\n- 当id=2上线之后\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/c2a2fd17956846d6be96745e452987fd.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP55Sf5Yeh5LiA,size_20,color_FFFFFF,t_70,g_se,x_16)\n\n- 再次发消息，就是在线应答了\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/715dee6ffb224f77a788a80e17539cb3.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP55Sf5Yeh5LiA,size_20,color_FFFFFF,t_70,g_se,x_16)\n\n- 这边就实时接受到消息了\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/4f0495ef968940a28b49e0c5b3e9f346.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP55Sf5Yeh5LiA,size_20,color_FFFFFF,t_70,g_se,x_16)\n\n- 获取历史信息\n\n![在这里插入图片描述](https://img-blog.csdnimg.cn/2e88c30fa5ce47ce94b681a5ffeafb88.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5bCP55Sf5Yeh5LiA,size_20,color_FFFFFF,t_70,g_se,x_16)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocainecong%2Fgin-chat-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcocainecong%2Fgin-chat-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocainecong%2Fgin-chat-demo/lists"}