From a26eba1af2b72545b65b4e3f6813f22d21ac022d Mon Sep 17 00:00:00 2001 From: li1553770945 <1553770945@qq.com> Date: Sun, 23 Apr 2023 18:36:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(im):=E4=BC=98=E5=8C=96im=E4=BD=93=E9=AA=8C?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Ajson=E6=B6=88=E6=81=AF=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/container/container.go | 4 + biz/container/wire.go | 6 + biz/container/wire_gen.go | 8 +- biz/infra/cache/go-cache.go | 11 ++ biz/infra/log/log.go | 33 +++- biz/internal/domain/chat.go | 31 ++++ biz/internal/dto/chat.go | 11 ++ biz/internal/service/chat/chat.go | 223 +++++++++++++++++++++++++ biz/internal/service/chat/interface.go | 27 +++ go.mod | 4 + go.sum | 8 + router.go | 10 ++ 12 files changed, 373 insertions(+), 3 deletions(-) create mode 100644 biz/infra/cache/go-cache.go create mode 100644 biz/internal/domain/chat.go create mode 100644 biz/internal/dto/chat.go create mode 100644 biz/internal/service/chat/chat.go create mode 100644 biz/internal/service/chat/interface.go diff --git a/biz/container/container.go b/biz/container/container.go index 8c13de3..910c357 100644 --- a/biz/container/container.go +++ b/biz/container/container.go @@ -2,6 +2,7 @@ package container import ( "personal-page-be/biz/infra/config" + "personal-page-be/biz/internal/service/chat" "personal-page-be/biz/internal/service/file" "personal-page-be/biz/internal/service/global_service" "personal-page-be/biz/internal/service/message" @@ -14,12 +15,14 @@ type Container struct { FileService file.IFileService GlobalService global_service.IGlobalService MessageService message.IMessageService + ChatService chat.IChatService } func NewContainer(config *config.Config, userService user.IUserService, fileService file.IFileService, globalService global_service.IGlobalService, messageService message.IMessageService, + chatService chat.IChatService, ) *Container { return &Container{ Config: config, @@ -27,6 +30,7 @@ func NewContainer(config *config.Config, userService user.IUserService, FileService: fileService, GlobalService: globalService, MessageService: messageService, + ChatService: chatService, } } diff --git a/biz/container/wire.go b/biz/container/wire.go index c8e2e21..a223c28 100644 --- a/biz/container/wire.go +++ b/biz/container/wire.go @@ -5,9 +5,12 @@ package container import ( "github.com/google/wire" + "personal-page-be/biz/infra/cache" "personal-page-be/biz/infra/config" "personal-page-be/biz/infra/database" + "personal-page-be/biz/infra/log" "personal-page-be/biz/internal/repo" + "personal-page-be/biz/internal/service/chat" "personal-page-be/biz/internal/service/file" "personal-page-be/biz/internal/service/global_service" "personal-page-be/biz/internal/service/message" @@ -20,6 +23,8 @@ func GetContainer(path string) *Container { //infra config.InitConfig, database.NewDatabase, + cache.NewCache, + log.NewLogger, //repo repo.NewRepository, @@ -29,6 +34,7 @@ func GetContainer(path string) *Container { file.NewFileService, global_service.NewGlobalService, message.NewMessageService, + chat.NewChatService, NewContainer, )) diff --git a/biz/container/wire_gen.go b/biz/container/wire_gen.go index 5016d07..47cca97 100644 --- a/biz/container/wire_gen.go +++ b/biz/container/wire_gen.go @@ -7,9 +7,12 @@ package container import ( + "personal-page-be/biz/infra/cache" "personal-page-be/biz/infra/config" "personal-page-be/biz/infra/database" + "personal-page-be/biz/infra/log" "personal-page-be/biz/internal/repo" + "personal-page-be/biz/internal/service/chat" "personal-page-be/biz/internal/service/file" "personal-page-be/biz/internal/service/global_service" "personal-page-be/biz/internal/service/message" @@ -26,6 +29,9 @@ func GetContainer(path string) *Container { iFileService := file.NewFileService(iRepository) iGlobalService := global_service.NewGlobalService(iRepository) iMessageService := message.NewMessageService(iRepository, configConfig) - container := NewContainer(configConfig, iUserService, iFileService, iGlobalService, iMessageService) + cacheCache := cache.NewCache() + logger := log.NewLogger() + iChatService := chat.NewChatService(cacheCache, logger) + container := NewContainer(configConfig, iUserService, iFileService, iGlobalService, iMessageService, iChatService) return container } diff --git a/biz/infra/cache/go-cache.go b/biz/infra/cache/go-cache.go new file mode 100644 index 0000000..1d725b3 --- /dev/null +++ b/biz/infra/cache/go-cache.go @@ -0,0 +1,11 @@ +package cache + +import ( + "github.com/patrickmn/go-cache" + "time" +) + +func NewCache() *cache.Cache { + c := cache.New(1*time.Hour, 2*time.Hour) + return c +} diff --git a/biz/infra/log/log.go b/biz/infra/log/log.go index 71a5059..d86c662 100644 --- a/biz/infra/log/log.go +++ b/biz/infra/log/log.go @@ -1,10 +1,39 @@ package log import ( + "fmt" "github.com/sirupsen/logrus" + "os" + "path/filepath" + "runtime" ) +func getLogLevel() logrus.Level { + // 设置日志级别,可以根据需要修改 + return logrus.DebugLevel +} + +func getLogFormatter() logrus.Formatter { + // 定义日志输出格式 + return &logrus.TextFormatter{ + FullTimestamp: true, + TimestampFormat: "2006-01-02 15:04:05", //时间格式, + CallerPrettyfier: callerPrettyfier, + } +} + +func callerPrettyfier(f *runtime.Frame) (string, string) { + // 格式化输出文件名和行号 + filename := filepath.Base(f.File) + return fmt.Sprintf("%s:%d", filename, f.Line), "" +} + func NewLogger() *logrus.Logger { - log := logrus.New() - return log + // 初始化日志 + logger := logrus.New() + logger.SetLevel(getLogLevel()) + logger.SetOutput(os.Stdout) + logger.SetFormatter(getLogFormatter()) + + return logger } diff --git a/biz/internal/domain/chat.go b/biz/internal/domain/chat.go new file mode 100644 index 0000000..fc45de0 --- /dev/null +++ b/biz/internal/domain/chat.go @@ -0,0 +1,31 @@ +package domain + +import ( + "github.com/hertz-contrib/websocket" + "golang.org/x/sync/semaphore" + "sync" + "time" +) + +type ChatMessageEntity struct { + Type string `json:"type"` + Data string `json:"data"` + Time time.Time `json:"time"` + ErrorMsg string `json:"error_msg"` +} + +type ChatEntity struct { + ChatID string + CreaterID string + JoinerID string + CreaterMessageLock sync.Mutex + JoinerMessageLock sync.Mutex + CreaterMessageWriteSem *semaphore.Weighted + CreaterMessageReadSem *semaphore.Weighted + JoinerMessageWriteSem *semaphore.Weighted + JoinerMessageReadSem *semaphore.Weighted + CreaterConn *websocket.Conn + JoinerConn *websocket.Conn + MessageSendByCreater []*ChatMessageEntity + MessageSendByJoiner []*ChatMessageEntity +} diff --git a/biz/internal/dto/chat.go b/biz/internal/dto/chat.go new file mode 100644 index 0000000..e397325 --- /dev/null +++ b/biz/internal/dto/chat.go @@ -0,0 +1,11 @@ +package dto + +type SendMessageReq struct { + ClientID string `json:"client_id"` + Message string `json:"message"` + ChatID string `json:"chat_id"` +} + +type JoinChatReq struct { + ChatID string `json:"chat_id"` +} diff --git a/biz/internal/service/chat/chat.go b/biz/internal/service/chat/chat.go new file mode 100644 index 0000000..e5903a2 --- /dev/null +++ b/biz/internal/service/chat/chat.go @@ -0,0 +1,223 @@ +package chat + +import ( + "context" + "encoding/json" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/common/utils" + "github.com/hertz-contrib/websocket" + "github.com/patrickmn/go-cache" + "personal-page-be/biz/internal/domain" + U "personal-page-be/biz/internal/utils" + "time" +) + +func (s *ChatService) CreateChat(ctx context.Context, c *app.RequestContext) { + var upgrader = websocket.HertzUpgrader{ + CheckOrigin: func(ctx *app.RequestContext) bool { + return true + }, + } + + var chatID string + for { + chatID = U.RandSeq(4) + _, found := s.Cache.Get(chatID) + if !found { + break + } + } + var chatEntity domain.ChatEntity + err := s.Cache.Add(chatID, &chatEntity, cache.DefaultExpiration) + if err != nil { + c.JSON(200, utils.H{"code": 5001, "msg": err.Error()}) + return + } + chatEntity.ChatID = chatID + chatEntity.CreaterID = U.RandSeq(10) + + err = upgrader.Upgrade(c, func(conn *websocket.Conn) { + s.MessageHandler(conn, &chatEntity, "creater") + }) + if err != nil { + s.Log.Error("update to websocket failed:", err.Error()) + c.JSON(200, utils.H{"code": 5001, "msg": err.Error()}) + return + } + //c.JSON(200, utils.H{"code": 0, "msg": "创建成功", "data": utils.H{"chat_id": chatEntity.ChatID, "client_id": chatEntity.CreaterID}}) +} +func (s *ChatService) JoinChat(ctx context.Context, c *app.RequestContext) { + var upgrader = websocket.HertzUpgrader{ + CheckOrigin: func(ctx *app.RequestContext) bool { + return true + }, + } + ChatID := c.DefaultQuery("chat_id", "") + + chatInterface, found := s.Cache.Get(ChatID) + if !found { + c.JSON(200, utils.H{"code": 4004, "msg": "未找到相关chat"}) + return + } + + var chatEntity *domain.ChatEntity + if entity, ok := chatInterface.(*domain.ChatEntity); ok { + chatEntity = entity + } else { + c.JSON(200, utils.H{"code": 5001, "msg": "内部错误,chatInterface断言失败"}) + return + } + + chatEntity.JoinerID = U.RandSeq(10) + err := upgrader.Upgrade(c, func(conn *websocket.Conn) { + s.MessageHandler(conn, chatEntity, "joiner") + }) + if err != nil { + c.JSON(200, utils.H{"code": 5001, "msg": err.Error()}) + return + } + +} + +func (s *ChatService) MessageHandler(recvConn *websocket.Conn, chatEntity *domain.ChatEntity, role string) { + + var msgEntity domain.ChatMessageEntity + msgEntity.Data = chatEntity.ChatID + msgEntity.Type = "chat_id" + msgEntity.Time = time.Now() + jsonBytes, _ := json.Marshal(msgEntity) + err := recvConn.WriteMessage(websocket.TextMessage, jsonBytes) + if err != nil { + s.Log.Error("send chat id failed:", err.Error()) + return + } + + msgEntity.Type = "client_id" + msgEntity.Time = time.Now() + + if role == "creater" { + msgEntity.Data = chatEntity.CreaterID + chatEntity.CreaterConn = recvConn + } else { + msgEntity.Data = chatEntity.JoinerID + chatEntity.JoinerConn = recvConn + } + + jsonBytes, _ = json.Marshal(msgEntity) + err = recvConn.WriteMessage(websocket.TextMessage, jsonBytes) + if err != nil { + s.Log.Error("send client id failed:", err.Error()) + } + for { + var result map[string]interface{} + + mt, message, err := recvConn.ReadMessage() + if err != nil { + s.Log.Error("receive msg failed:", err.Error()) + if chatEntity.JoinerConn != nil { + chatEntity.JoinerConn.Close() + chatEntity.JoinerConn = nil + } + if chatEntity.CreaterConn != nil { + chatEntity.CreaterConn.Close() + chatEntity.CreaterConn = nil + } + return + } + if err = json.Unmarshal([]byte(message), &result); err != nil { + s.Log.Error("convert received message to json failed,message:", message) + continue + } + + if mt == websocket.TextMessage { + var sendMsgEntity domain.ChatMessageEntity + sendMsgEntity.Data = result["data"].(string) + sendMsgEntity.Type = "client_message" + sendMsgEntity.Time = time.Now() + jsonBytes, err := json.Marshal(sendMsgEntity) + if err != nil { + s.Log.Error("convert sendMsgEntity to json failed", err.Error()) + } + + if role == "creater" { + + if chatEntity.JoinerConn != nil { // 如果发送方已经上线 + err = chatEntity.JoinerConn.WriteMessage(mt, jsonBytes) + if err != nil { + s.Log.Error("send msg to creater failed", err.Error()) + } + } else { + sendMsgEntity.Data = "" + sendMsgEntity.Type = "error" + sendMsgEntity.Time = time.Now() + sendMsgEntity.ErrorMsg = "对方未上线,发送失败" + jsonBytes, _ := json.Marshal(sendMsgEntity) + recvConn.WriteMessage(websocket.TextMessage, jsonBytes) + } + + } else { // 如果是接收方 + if chatEntity.CreaterConn != nil { + err = chatEntity.CreaterConn.WriteMessage(mt, jsonBytes) + if err != nil { + s.Log.Error("send msg to joiner failed", err.Error()) + } + } + } + } + + } +} +func (s *ChatService) GetMessageList(ctx context.Context, c *app.RequestContext) { + chatID := c.DefaultQuery("chat_id", "") + id := c.DefaultQuery("client_id", "") + chatInterface, found := s.Cache.Get(chatID) + if !found { + c.JSON(200, utils.H{"code": 4004, "msg": "chat不存在或已结束"}) + return + } + var chatEntity *domain.ChatEntity + if entity, ok := chatInterface.(*domain.ChatEntity); ok { + chatEntity = entity + } else { + c.JSON(200, utils.H{"code": 5001, "msg": "内部错误,chatInterface断言失败"}) + return + } + var messages []*domain.ChatMessageEntity + if id == chatEntity.JoinerID { + chatEntity.CreaterMessageLock.Lock() + messages = chatEntity.MessageSendByCreater + + chatEntity.CreaterMessageLock.Unlock() + c.JSON(200, utils.H{"code": 0, "data": messages}) + } else if id == chatEntity.CreaterID { + chatEntity.JoinerMessageLock.Lock() + messages = chatEntity.MessageSendByJoiner + chatEntity.JoinerMessageLock.Unlock() + c.JSON(200, utils.H{"code": 0, "data": messages}) + } else { + c.JSON(200, utils.H{"code": 4004, "msg": "无效的ID"}) + } +} +func (s *ChatService) CloseChat(ctx context.Context, c *app.RequestContext) { + chatID := string(c.FormValue("chat_id")) + id := string(c.FormValue("id")) + chatInterface, found := s.Cache.Get(chatID) + if !found { + c.JSON(200, utils.H{"code": 4004, "msg": "chat不存在或已结束"}) + return + } + var chatEntity *domain.ChatEntity + if entity, ok := chatInterface.(*domain.ChatEntity); ok { + chatEntity = entity + } else { + c.JSON(200, utils.H{"code": 5001, "msg": "内部错误,chatInterface断言失败"}) + return + } + + if id != chatEntity.CreaterID { + c.JSON(200, utils.H{"code": 4003, "msg": "无权进行操作"}) + return + } + s.Cache.Delete(chatID) + c.JSON(200, utils.H{"code": 0, "msg": "操作成功"}) +} diff --git a/biz/internal/service/chat/interface.go b/biz/internal/service/chat/interface.go new file mode 100644 index 0000000..403fc96 --- /dev/null +++ b/biz/internal/service/chat/interface.go @@ -0,0 +1,27 @@ +package chat + +import ( + "context" + "github.com/cloudwego/hertz/pkg/app" + "github.com/patrickmn/go-cache" + "github.com/sirupsen/logrus" +) + +type ChatService struct { + Cache *cache.Cache + Log *logrus.Logger +} + +type IChatService interface { + CreateChat(ctx context.Context, c *app.RequestContext) + JoinChat(ctx context.Context, c *app.RequestContext) + CloseChat(ctx context.Context, c *app.RequestContext) +} + +func NewChatService(cache *cache.Cache, log *logrus.Logger) IChatService { + s := &ChatService{ + Cache: cache, + Log: log, + } + return s +} diff --git a/go.mod b/go.mod index b7b90f8..9776c14 100644 --- a/go.mod +++ b/go.mod @@ -7,9 +7,12 @@ require ( github.com/google/uuid v1.3.0 github.com/google/wire v0.5.0 github.com/hertz-contrib/sessions v1.0.1 + github.com/hertz-contrib/websocket v0.0.1 + github.com/patrickmn/go-cache v2.1.0+incompatible github.com/robfig/cron/v3 v3.0.1 github.com/sirupsen/logrus v1.9.0 golang.org/x/crypto v0.6.0 + golang.org/x/sync v0.1.0 gopkg.in/yaml.v3 v3.0.1 gorm.io/driver/postgres v1.4.8 gorm.io/gorm v1.24.5 @@ -35,6 +38,7 @@ require ( github.com/jinzhu/now v1.1.5 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/nyaruka/phonenumbers v1.0.55 // indirect + github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect github.com/tidwall/gjson v1.13.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect diff --git a/go.sum b/go.sum index 2abeaaf..8da9b0f 100644 --- a/go.sum +++ b/go.sum @@ -48,6 +48,8 @@ github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8 h1:yE9ULgp02BhY github.com/henrylee2cn/goutil v0.0.0-20210127050712-89660552f6f8/go.mod h1:Nhe/DM3671a5udlv2AdV2ni/MZzgfv2qrPL5nIi3EGQ= github.com/hertz-contrib/sessions v1.0.1 h1:2puqvNqzyuPC3+5gzMRS+xhvGdNq3Ux7OVEewLSJbAk= github.com/hertz-contrib/sessions v1.0.1/go.mod h1:gyVq7zq5emvSTLpp4VrlLOXjnajorYZ1hH4ZSX9Afb0= +github.com/hertz-contrib/websocket v0.0.1 h1:NVtGICwqFyAXPotY/KGwYMXSi2l1S+vM6JJMqkIu0Ho= +github.com/hertz-contrib/websocket v0.0.1/go.mod h1:rBtjAV7auKVBjtKvuQX9zzR8gZ2zKPHybPodAhqdbVo= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= @@ -75,12 +77,16 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/nyaruka/phonenumbers v1.0.55 h1:bj0nTO88Y68KeUQ/n3Lo2KgK7lM1hF7L9NFuwcCl3yg= github.com/nyaruka/phonenumbers v1.0.55/go.mod h1:sDaTZ/KPX5f8qyV9qN+hIm+4ZBARJrupC6LuhshJq1U= +github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= +github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d h1:Q+gqLBOPkFGHyCJxXMRqtUgUbTjI8/Ze8vu8GGyNFwo= +github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d/go.mod h1:Gy+0tqhJvgGlqnTF8CVGP0AaGRjwBtXs/a5PA0Y3+A4= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -105,6 +111,7 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/arch v0.0.0-20210923205945-b76863e36670 h1:18EFjUmQOcUvxNYSkA6jO9VAiXCnxFY6NyDX0bHDmkU= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= @@ -121,6 +128,7 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/router.go b/router.go index eaa463f..cb9eddb 100644 --- a/router.go +++ b/router.go @@ -26,6 +26,16 @@ func customizedRegister(r *server.Hertz) { api.POST("/message", App.MessageService.SaveMessage) api.GET("/reply", App.MessageService.GetReply) api.POST("/reply", append(middlewire.UserMiddleware(), App.MessageService.AddReply)...) + + //api.POST("/chat-message", App.ChatService.SendMessage) + //api.GET("/chat-message", App.ChatService.GetMessageList) + api.POST("/close-chat", App.ChatService.CloseChat) + } + + socket := r.Group("/socket") + { + socket.GET("/new-chat", App.ChatService.CreateChat) + socket.GET("/join-chat", App.ChatService.JoinChat) } }