Giter Site home page Giter Site logo

cocainecong / gin-chat-demo Goto Github PK

View Code? Open in Web Editor NEW
120.0 2.0 38.0 36 KB

gin+websocket+mongodb实现 IM 即时聊天系统,基于WS连接的即时聊天,支持单聊,在线回复以及历史记录查询

License: MIT License

Go 100.00%
gin go im mongodb redis tcp websocket

gin-chat-demo's Introduction

gin-chat-demo

gin+websocket+mongodb实现 IM 即时聊天系统

这个项目是基于WebSocket + MongoDB + MySQL + Redis。 业务逻辑很简单,只是两人的聊天。

  • MySQL 用来存储用户基本信息
  • MongoDB 用来存放用户聊天信息
  • Redis 用来存储处理过期信息

项目教程

B站:https://www.bilibili.com/video/BV1BP4y1H7gV

博客:https://blog.csdn.net/weixin_45304503/article/details/121787022

项目结构

gin-chat-demo/
├── cache
├── conf
├── e
├── model
├── router
└── service
  • cache : 放置redis配置
  • conf : 放置配置文件
  • model : 数据库模型
  • pkg : 防止一些错误码
  • router : 路由模块
  • service :服务模块

项目功能

  • 两人通信
  • 在线、不在线应答
  • 查看历史聊天记录

配置文件

  • conf/config.ini
#debug开发模式,release生产模式
[service]
AppMode = debug
HttpPort = :3000 
# 运行端口号 3000端口

[mysql]
Db = mysql
DbHost = "" 
# mysql的ip地址
DbPort = ""
# mysql的端口号,默认3306
DbUser = ""
# mysql user
DbPassWord = ""
# mysql password
DbName = ""
# 数据库名字

[redis]
RedisDb = ""
# redis 名字
RedisAddr = ""
# redis 地址
RedisPw = ""
# redis 密码
RedisDbName = ""
# redis 数据库名

[MongoDB]
MongoDBName =  ""
MongoDBAddr = ""
MongoDBPwd = ""
MongoDBPort = ""

项目运行

  • 下载依赖
go mod tidy
  • 执行
go run main.go

演示

  • 测试http连接

在这里插入图片描述

  • 进行ws连接,连接服务器

在这里插入图片描述

  • 当id=1上线,但是id=2没上线的时候发送消息

在这里插入图片描述

  • 当id=2上线之后

在这里插入图片描述

  • 再次发消息,就是在线应答了

在这里插入图片描述

  • 这边就实时接受到消息了

在这里插入图片描述

  • 获取历史信息

在这里插入图片描述

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.