瀏覽代碼

[fix]规范化

Zhangzhenhua 2 周之前
父節點
當前提交
46ec575994

+ 3 - 3
api/websocket/websocket.go → api/chat/chat.go

@@ -2,14 +2,14 @@
 // Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
 // =================================================================================
 
-package websocket
+package chat
 
 import (
 	"context"
 
-	"cris/api/websocket/v1"
+	"cris/api/chat/v1"
 )
 
-type IWebsocketV1 interface {
+type IChatV1 interface {
 	Chat(ctx context.Context, req *v1.ChatReq) (res *v1.ChatRes, err error)
 }

+ 0 - 0
api/websocket/v1/chat.go → api/chat/v1/chat.go


+ 1 - 1
internal/controller/websocket/websocket.go → internal/controller/chat/chat.go

@@ -2,4 +2,4 @@
 // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
 // =================================================================================
 
-package websocket
+package chat

+ 3 - 3
internal/controller/websocket/websocket_new.go → internal/controller/chat/chat_new.go

@@ -2,14 +2,14 @@
 // This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
 // =================================================================================
 
-package websocket
+package chat
 
 import (
-	"cris/api/websocket"
+	"cris/api/chat"
 )
 
 type ControllerV1 struct{}
 
-func NewV1() websocket.IWebsocketV1 {
+func NewV1() chat.IChatV1 {
 	return &ControllerV1{}
 }

+ 2 - 2
internal/controller/websocket/websocket_v1_chat.go → internal/controller/chat/chat_v1_chat.go

@@ -1,4 +1,4 @@
-package websocket
+package chat
 
 import (
 	"context"
@@ -6,7 +6,7 @@ import (
 	"github.com/gogf/gf/v2/errors/gcode"
 	"github.com/gogf/gf/v2/errors/gerror"
 
-	"cris/api/websocket/v1"
+	"cris/api/chat/v1"
 )
 
 func (c *ControllerV1) Chat(ctx context.Context, req *v1.ChatReq) (res *v1.ChatRes, err error) {

+ 9 - 4
internal/logic/websocket/websocket.go → internal/logic/chat/chat.go

@@ -1,6 +1,7 @@
-package logic
+package chat
 
 import (
+	"context"
 	"log"
 	"net/http"
 	"sync"
@@ -8,7 +9,7 @@ import (
 	"github.com/gogf/gf/v2/net/ghttp"
 	"github.com/gorilla/websocket"
 
-	v1 "cris/api/websocket/v1"
+	v1 "cris/api/chat/v1"
 )
 
 // 维护 WebSocket 客户端连接池
@@ -16,9 +17,13 @@ var clients = make(map[*websocket.Conn]bool)
 var broadcast = make(chan string) // 广播消息的通道
 var mu sync.Mutex                 //互斥锁
 
-type WebsocketService struct{}
+type chat struct{}
 
-func (s *WebsocketService) WebSocket(r *ghttp.Request, req *v1.ChatReq) {
+func New() *chat {
+	return &chat{}
+}
+
+func (s *chat) Chat(ctx context.Context, r *ghttp.Request, req *v1.ChatReq) {
 
 	// 升级 HTTP 请求为 WebSocket
 	upgrader := websocket.Upgrader{

+ 1 - 1
internal/logic/logic.go

@@ -5,6 +5,6 @@
 package logic
 
 import (
+	_ "cris/internal/logic/chat"
 	_ "cris/internal/logic/login"
-	_ "cris/internal/logic/websocket"
 )

+ 11 - 3
internal/logic/login/login.go

@@ -1,12 +1,20 @@
-package logic
+package login
 
 import (
+	"context"
+
 	v1 "cris/api/login/v1"
 )
 
-type LoginLogic struct{}
+type (
+	slogin struct{}
+)
+
+func New() *slogin {
+	return &slogin{}
+}
 
-func (s *LoginLogic) Login(req *v1.LoginReq) *v1.LoginRes {
+func (s *slogin) Login(ctx context.Context, req *v1.LoginReq) *v1.LoginRes {
 	// 在这里进行具体的逻辑处理
 
 	return &v1.LoginRes{

+ 8 - 0
internal/service/chat.go

@@ -0,0 +1,8 @@
+// ================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// You can delete these comments if you wish manually maintain this interface file.
+// ================================================================================
+
+package service
+
+type ()

+ 5 - 0
internal/service/login.go

@@ -1,3 +1,8 @@
+// ================================================================================
+// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT.
+// You can delete these comments if you wish manually maintain this interface file.
+// ================================================================================
+
 package service
 
 type ()

+ 0 - 3
internal/service/websocket.go

@@ -1,3 +0,0 @@
-package service
-
-type ()