diff --git a/2024-Insomnia-Backend/.idea/.gitignore b/2024-Insomnia-Backend/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/2024-Insomnia-Backend/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/2024-Insomnia-Backend/.idea/Insomnia.iml b/2024-Insomnia-Backend/.idea/Insomnia.iml
new file mode 100644
index 0000000..5e764c4
--- /dev/null
+++ b/2024-Insomnia-Backend/.idea/Insomnia.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2024-Insomnia-Backend/.idea/modules.xml b/2024-Insomnia-Backend/.idea/modules.xml
new file mode 100644
index 0000000..581fac2
--- /dev/null
+++ b/2024-Insomnia-Backend/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2024-Insomnia-Backend/app/request/auth.go b/2024-Insomnia-Backend/app/api/request/auth.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/request/auth.go
rename to 2024-Insomnia-Backend/app/api/request/auth.go
diff --git a/2024-Insomnia-Backend/app/request/email.go b/2024-Insomnia-Backend/app/api/request/email.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/request/email.go
rename to 2024-Insomnia-Backend/app/api/request/email.go
diff --git a/2024-Insomnia-Backend/app/request/likes.go b/2024-Insomnia-Backend/app/api/request/likes.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/request/likes.go
rename to 2024-Insomnia-Backend/app/api/request/likes.go
diff --git a/2024-Insomnia-Backend/app/request/myMessage.go b/2024-Insomnia-Backend/app/api/request/myMessage.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/request/myMessage.go
rename to 2024-Insomnia-Backend/app/api/request/myMessage.go
diff --git a/2024-Insomnia-Backend/app/request/post.go b/2024-Insomnia-Backend/app/api/request/post.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/request/post.go
rename to 2024-Insomnia-Backend/app/api/request/post.go
diff --git a/2024-Insomnia-Backend/app/request/repost.go b/2024-Insomnia-Backend/app/api/request/repost.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/request/repost.go
rename to 2024-Insomnia-Backend/app/api/request/repost.go
diff --git a/2024-Insomnia-Backend/app/api/request/task.go b/2024-Insomnia-Backend/app/api/request/task.go
new file mode 100644
index 0000000..3e4bc5f
--- /dev/null
+++ b/2024-Insomnia-Backend/app/api/request/task.go
@@ -0,0 +1,5 @@
+package request
+
+type UpdateTaskNumber struct {
+ Num uint `json:"num"`
+}
diff --git a/2024-Insomnia-Backend/app/request/thread.go b/2024-Insomnia-Backend/app/api/request/thread.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/request/thread.go
rename to 2024-Insomnia-Backend/app/api/request/thread.go
diff --git a/2024-Insomnia-Backend/app/response/auth.go b/2024-Insomnia-Backend/app/api/response/auth.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/response/auth.go
rename to 2024-Insomnia-Backend/app/api/response/auth.go
diff --git a/2024-Insomnia-Backend/app/response/likes.go b/2024-Insomnia-Backend/app/api/response/likes.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/response/likes.go
rename to 2024-Insomnia-Backend/app/api/response/likes.go
diff --git a/2024-Insomnia-Backend/app/response/message.go b/2024-Insomnia-Backend/app/api/response/message.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/response/message.go
rename to 2024-Insomnia-Backend/app/api/response/message.go
diff --git a/2024-Insomnia-Backend/app/response/post.go b/2024-Insomnia-Backend/app/api/response/post.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/response/post.go
rename to 2024-Insomnia-Backend/app/api/response/post.go
diff --git a/2024-Insomnia-Backend/app/response/repost.go b/2024-Insomnia-Backend/app/api/response/repost.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/response/repost.go
rename to 2024-Insomnia-Backend/app/api/response/repost.go
diff --git a/2024-Insomnia-Backend/app/response/response.go b/2024-Insomnia-Backend/app/api/response/response.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/response/response.go
rename to 2024-Insomnia-Backend/app/api/response/response.go
diff --git a/2024-Insomnia-Backend/app/response/task.go b/2024-Insomnia-Backend/app/api/response/task.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/response/task.go
rename to 2024-Insomnia-Backend/app/api/response/task.go
diff --git a/2024-Insomnia-Backend/app/response/thread.go b/2024-Insomnia-Backend/app/api/response/thread.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/response/thread.go
rename to 2024-Insomnia-Backend/app/api/response/thread.go
diff --git a/2024-Insomnia-Backend/app/routers/auth.go b/2024-Insomnia-Backend/app/api/routers/auth.go
similarity index 89%
rename from 2024-Insomnia-Backend/app/routers/auth.go
rename to 2024-Insomnia-Backend/app/api/routers/auth.go
index 6819f37..e89bf17 100644
--- a/2024-Insomnia-Backend/app/routers/auth.go
+++ b/2024-Insomnia-Backend/app/api/routers/auth.go
@@ -1,7 +1,7 @@
package routers
import (
- "Insomnia/app/core/middlewares"
+ "Insomnia/app/infrastructure/middlewares"
)
func (r *router) useAuth() {
diff --git a/2024-Insomnia-Backend/app/routers/common.go b/2024-Insomnia-Backend/app/api/routers/common.go
similarity index 81%
rename from 2024-Insomnia-Backend/app/routers/common.go
rename to 2024-Insomnia-Backend/app/api/routers/common.go
index 309cdd2..1d0dac3 100644
--- a/2024-Insomnia-Backend/app/routers/common.go
+++ b/2024-Insomnia-Backend/app/api/routers/common.go
@@ -1,6 +1,8 @@
package routers
-import "Insomnia/app/core/middlewares"
+import (
+ "Insomnia/app/infrastructure/middlewares"
+)
// 通用的路由
func (r *router) useCommon() {
diff --git a/2024-Insomnia-Backend/app/routers/index.go b/2024-Insomnia-Backend/app/api/routers/index.go
similarity index 97%
rename from 2024-Insomnia-Backend/app/routers/index.go
rename to 2024-Insomnia-Backend/app/api/routers/index.go
index f660007..824be8e 100644
--- a/2024-Insomnia-Backend/app/routers/index.go
+++ b/2024-Insomnia-Backend/app/api/routers/index.go
@@ -43,4 +43,6 @@ func Load(e *gin.Engine) {
r.useCommon()
//启动消息的路由
r.useMyMessage()
+ //启用Tube
+ r.useTube()
}
diff --git a/2024-Insomnia-Backend/app/routers/myMessage.go b/2024-Insomnia-Backend/app/api/routers/myMessage.go
similarity index 89%
rename from 2024-Insomnia-Backend/app/routers/myMessage.go
rename to 2024-Insomnia-Backend/app/api/routers/myMessage.go
index 42ee8c9..c997469 100644
--- a/2024-Insomnia-Backend/app/routers/myMessage.go
+++ b/2024-Insomnia-Backend/app/api/routers/myMessage.go
@@ -1,6 +1,8 @@
package routers
-import "Insomnia/app/core/middlewares"
+import (
+ "Insomnia/app/infrastructure/middlewares"
+)
func (r *router) useMyMessage() {
useMyMessage := r.Group("myMessage")
diff --git a/2024-Insomnia-Backend/app/routers/post.go b/2024-Insomnia-Backend/app/api/routers/post.go
similarity index 89%
rename from 2024-Insomnia-Backend/app/routers/post.go
rename to 2024-Insomnia-Backend/app/api/routers/post.go
index b0a40a4..cc7a6ad 100644
--- a/2024-Insomnia-Backend/app/routers/post.go
+++ b/2024-Insomnia-Backend/app/api/routers/post.go
@@ -1,6 +1,8 @@
package routers
-import "Insomnia/app/core/middlewares"
+import (
+ "Insomnia/app/infrastructure/middlewares"
+)
// usePost 回复的路由
func (r *router) usePost() {
diff --git a/2024-Insomnia-Backend/app/routers/repost.go b/2024-Insomnia-Backend/app/api/routers/repost.go
similarity index 90%
rename from 2024-Insomnia-Backend/app/routers/repost.go
rename to 2024-Insomnia-Backend/app/api/routers/repost.go
index 8a43f22..963bfea 100644
--- a/2024-Insomnia-Backend/app/routers/repost.go
+++ b/2024-Insomnia-Backend/app/api/routers/repost.go
@@ -1,6 +1,8 @@
package routers
-import "Insomnia/app/core/middlewares"
+import (
+ "Insomnia/app/infrastructure/middlewares"
+)
// useRePost re回复的路由
func (r *router) useRePost() {
diff --git a/2024-Insomnia-Backend/app/routers/task.go b/2024-Insomnia-Backend/app/api/routers/task.go
similarity index 62%
rename from 2024-Insomnia-Backend/app/routers/task.go
rename to 2024-Insomnia-Backend/app/api/routers/task.go
index 08da116..48d4781 100644
--- a/2024-Insomnia-Backend/app/routers/task.go
+++ b/2024-Insomnia-Backend/app/api/routers/task.go
@@ -1,11 +1,12 @@
package routers
-import "Insomnia/app/core/middlewares"
+import (
+ "Insomnia/app/infrastructure/middlewares"
+)
// useTask 获取当日数据的路由
func (r *router) useTask() {
- taskRouter := r.Group("task1")
- taskRouter.POST("/getTask", middlewares.UseJwt(), r.task.GetTask)
+ taskRouter := r.Group("task")
taskRouter.POST("/upTask", middlewares.UseJwt(), r.task.UpTask)
taskRouter.POST("/getAllTask", middlewares.UseJwt(), r.task.GetAllTask)
}
diff --git a/2024-Insomnia-Backend/app/routers/thread.go b/2024-Insomnia-Backend/app/api/routers/thread.go
similarity index 91%
rename from 2024-Insomnia-Backend/app/routers/thread.go
rename to 2024-Insomnia-Backend/app/api/routers/thread.go
index 578226a..22efe03 100644
--- a/2024-Insomnia-Backend/app/routers/thread.go
+++ b/2024-Insomnia-Backend/app/api/routers/thread.go
@@ -1,6 +1,8 @@
package routers
-import "Insomnia/app/core/middlewares"
+import (
+ "Insomnia/app/infrastructure/middlewares"
+)
// useThread 帖子的路由
func (r *router) useThread() {
diff --git a/2024-Insomnia-Backend/app/api/routers/tube.go b/2024-Insomnia-Backend/app/api/routers/tube.go
new file mode 100644
index 0000000..20a4286
--- /dev/null
+++ b/2024-Insomnia-Backend/app/api/routers/tube.go
@@ -0,0 +1,8 @@
+package routers
+
+import "Insomnia/app/infrastructure/middlewares"
+
+func (r *router) useTube() {
+ tubeRouter := r.Group("tube")
+ tubeRouter.POST("/getQNToken", middlewares.UseJwt(), r.tube.GetQNToken)
+}
diff --git a/2024-Insomnia-Backend/app/controller/auth.go b/2024-Insomnia-Backend/app/controller/auth.go
index c2a2026..866d0d6 100644
--- a/2024-Insomnia-Backend/app/controller/auth.go
+++ b/2024-Insomnia-Backend/app/controller/auth.go
@@ -1,11 +1,11 @@
package controller
import (
- "Insomnia/app/common/tool"
- . "Insomnia/app/core/helper"
- . "Insomnia/app/request"
- . "Insomnia/app/response"
+ . "Insomnia/app/api/request"
+ . "Insomnia/app/api/response"
+ . "Insomnia/app/infrastructure/helper"
"Insomnia/app/service"
+ "Insomnia/app/utility/tool"
"fmt"
"github.com/gin-gonic/gin"
)
@@ -20,8 +20,8 @@ var authService *service.AuthService
// @Tags Auth
// @Accept json
// @Produce json
-// @Param email body string true "邮箱"
-// @Param password body string true "密码"
+// @Param email query string true "邮箱"
+// @Param password query string true "密码"
// @Success 200 {object} LoginResponse "登录成功"
// @Failure 400 {object} ErrorResponse "请求参数错误"
// @Failure 500 {object} ErrorResponse "内部错误"
@@ -55,10 +55,10 @@ func (a *Auth) Login(c *gin.Context) {
// @Tags Auth
// @Accept json
// @Produce json
-// @Param email body string true "邮箱"
-// @Param password body string true "密码"
-// @Param verificationCode body string true "验证码"
-// @Param avatar body string true "头像"
+// @Param email query string true "邮箱"
+// @Param password query string true "密码"
+// @Param verificationCode query string true "验证码"
+// @Param avatar query string false "头像"
// @Success 200 {object} LoginResponse "登录成功"
// @Failure 400 {object} ErrorResponse "请求参数错误"
// @Failure 500 {object} ErrorResponse "内部错误"
@@ -92,10 +92,10 @@ func (a *Auth) Signup(c *gin.Context) {
// @Tags Auth
// @Accept json
// @Produce json
-// @Param email body string true "邮箱"
-// @Param verificationCode body string true "验证码"
+// @Param email query string true "邮箱"
+// @Param verificationCode query string true "验证码"
// @Param Authorization header string true "jwt验证"
-// @Param newPassword body string true "新密码"
+// @Param newPassword query string true "新密码"
// @Success 200 {object} string "密码更改成功"
// @Failure 400 {object} ErrorResponse "请求参数错误"
// @Failure 500 {object} ErrorResponse "内部错误"
@@ -129,7 +129,7 @@ func (a *Auth) ChangePassword(c *gin.Context) {
// @Tags Auth
// @Accept json
// @Produce json
-// @Param newAvatar body string true "新头像"
+// @Param newAvatar query string true "新头像"
// @Param Authorization header string true "jwt验证"
// @Success 200 {object} string "头像更改成功"
// @Failure 400 {object} string "请求参数错误"
diff --git a/2024-Insomnia-Backend/app/controller/email.go b/2024-Insomnia-Backend/app/controller/email.go
index 3f1618b..3e29ac4 100644
--- a/2024-Insomnia-Backend/app/controller/email.go
+++ b/2024-Insomnia-Backend/app/controller/email.go
@@ -1,12 +1,12 @@
package controller
import (
- . "Insomnia/app/common/tool"
- . "Insomnia/app/core/config"
- . "Insomnia/app/core/helper"
- "Insomnia/app/models"
- . "Insomnia/app/request"
- . "Insomnia/app/response"
+ . "Insomnia/app/api/request"
+ . "Insomnia/app/api/response"
+ . "Insomnia/app/infrastructure/Email"
+ . "Insomnia/app/infrastructure/config"
+ . "Insomnia/app/infrastructure/helper"
+ . "Insomnia/app/utility/tool"
"fmt"
"github.com/gin-gonic/gin"
"github.com/jordan-wright/email"
@@ -23,7 +23,7 @@ type SendEmail struct{}
// @Accept json
// @Produce json
// @version 1.0
-// @Param email body SendEmailRequest true "邮箱"
+// @Param email query SendEmailRequest true "邮箱"
// @Success 200 {string} string "发送邮件成功"
// @Failure 404 {string} string "邮箱服务器出错"
// @Failure 500 {string} string "发送邮件失败"
@@ -52,7 +52,7 @@ func (e *SendEmail) SendEmail(c *gin.Context) {
return
}
//创造一个临时的CheckEmail
- Email := models.CheckEmail{
+ Email := CheckEmail{
Email: cp.Email,
VerificationCode: random,
}
diff --git a/2024-Insomnia-Backend/app/controller/myMessage.go b/2024-Insomnia-Backend/app/controller/myMessage.go
index 0e76e41..b96519f 100644
--- a/2024-Insomnia-Backend/app/controller/myMessage.go
+++ b/2024-Insomnia-Backend/app/controller/myMessage.go
@@ -1,9 +1,9 @@
package controller
import (
- . "Insomnia/app/core/helper"
- . "Insomnia/app/request"
- . "Insomnia/app/response"
+ . "Insomnia/app/api/request"
+ . "Insomnia/app/api/response"
+ . "Insomnia/app/infrastructure/helper"
"Insomnia/app/service"
"fmt"
"github.com/gin-gonic/gin"
@@ -14,6 +14,17 @@ type MyMessage struct{}
var myMessageService *service.MyMessageService
+// GetPostMessage 获取用户的评论消息
+// @Summary 获取用户的评论消息接口
+// @Description 获取用户的评论消息接口
+// @Tags MyMessage
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} MessageResponse "获取消息成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/myMessage/getPostMessage [post]
func (m *MyMessage) GetPostMessage(c *gin.Context) {
Uuid, _ := c.Get("Uuid")
uuid := Uuid.(string)
@@ -36,6 +47,18 @@ func (m *MyMessage) GetPostMessage(c *gin.Context) {
OkMsgData(c, "获取评论信息成功", rsp)
}
+// CheckPostMessage 查看用户的评论消息
+// @Summary 查看用户的评论消息接口
+// @Description 查看用户的评论消息接口
+// @Tags MyMessage
+// @Accept json
+// @Produce json
+// @Param id query string true "返回给你的post消息的id"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} MessageResponse "查看消息成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/myMessage/checkPostMessage [post]
func (m *MyMessage) CheckPostMessage(c *gin.Context) {
//定义一个Login请求类型的结构体
req := &CheckPostMessageReq{}
@@ -53,6 +76,17 @@ func (m *MyMessage) CheckPostMessage(c *gin.Context) {
OkMsg(c, "检查消息成功")
}
+// GetLikeMessage 获取用户的点赞消息
+// @Summary 获取用户的点赞消息接口
+// @Description 获取用户的点赞消息接口
+// @Tags MyMessage
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} MessageResponse "获取帖子成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/myMessage/getLikeMessage [post]
func (m *MyMessage) GetLikeMessage(c *gin.Context) {
Uuid, _ := c.Get("Uuid")
uuid := Uuid.(string)
@@ -78,6 +112,18 @@ func (m *MyMessage) GetLikeMessage(c *gin.Context) {
OkMsgData(c, "获取点赞消息成功", rsp)
}
+// CheckLikeMessage 查看用户的点赞消息
+// @Summary 查看用户的点赞消息接口
+// @Description 查看用户的点赞消息接口
+// @Tags MyMessage
+// @Accept json
+// @Produce json
+// @Param id query string true "返回给你的like消息的id"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} MessageResponse "查看消息成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/myMessage/checkLikeMessage [post]
func (m *MyMessage) CheckLikeMessage(c *gin.Context) {
//定义一个Login请求类型的结构体
req := &CheckLikeMessageReq{}
diff --git a/2024-Insomnia-Backend/app/controller/post.go b/2024-Insomnia-Backend/app/controller/post.go
index 87f2a88..b06c383 100644
--- a/2024-Insomnia-Backend/app/controller/post.go
+++ b/2024-Insomnia-Backend/app/controller/post.go
@@ -1,26 +1,46 @@
package controller
import (
+ request2 "Insomnia/app/api/request"
+ . "Insomnia/app/api/response"
+ . "Insomnia/app/infrastructure/helper"
+ "Insomnia/app/infrastructure/kafka"
+ "Insomnia/app/infrastructure/redis"
"Insomnia/app/models"
- "Insomnia/app/request"
- "Insomnia/app/response"
"Insomnia/app/service"
+ "encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
+ "sync"
)
+var lock1 sync.Mutex
+
type Post struct{}
var postService *service.PostService
+// CreatePost 创建回复
+// @Summary 用户创建回复接口
+// @Description 用户创建回复接口
+// @Tags Post
+// @Accept json
+// @Produce json
+// @Param tUuid query string true "帖子id"
+// @Param body query string true "回复内容"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} GetPostResponse "回复创建成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/post/createPost [post]
func (p *Post) CreatePost(c *gin.Context) {
//定义一个创建帖子请求的结构体
- req := &request.CreatePostReq{}
+ req := &request2.CreatePostReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
@@ -28,11 +48,11 @@ func (p *Post) CreatePost(c *gin.Context) {
uuid := Uuid.(string)
post, err := postService.CreatePost(uuid, *req)
if err != nil {
- response.FailMsgData(c, fmt.Sprintf("创建回复失败: %v", err), models.Post{})
+ FailMsgData(c, fmt.Sprintf("创建回复失败: %v", err), models.Post{})
return
}
- rsp := response.GetPostResponse{
+ rsp := GetPostResponse{
CreatedAt: post.CreatedAt.Format("2006-01-02 15:04"),
TUuid: post.TUuid,
UuId: post.Uuid,
@@ -40,23 +60,42 @@ func (p *Post) CreatePost(c *gin.Context) {
Likes: post.Likes,
Body: post.Body,
}
- response.FailMsgData(c, "创建回复成功", rsp)
+
+ err = redis.DelResp(post.TUuid)
+ if err != nil {
+ Danger(err, "删除对应post缓存数据失败")
+ }
+
+ OkMsgData(c, "创建回复成功", rsp)
return
}
+// ReadPost 读取回复
+// @Summary 用户读取回复接口
+// @Description 用户读取回复接口
+// @Tags Post
+// @Accept json
+// @Produce json
+// @Param pUuid query string true "回复id"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} GetPostResponse "回复读取成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/post/readPost [post]
func (p *Post) ReadPost(c *gin.Context) {
//定义一个寻找到帖子请求的结构体
- req := &request.FindPostReq{}
+ req := &request2.FindPostReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
+ //缓存未命中的话就从数据库中拿取
post, err := postService.ReadPost(req.PUuid)
if err != nil {
- response.FailMsgData(c, fmt.Sprintf("获取回复失败: %v", err), models.Post{})
+ FailMsgData(c, fmt.Sprintf("获取回复失败: %v", err), models.Post{})
return
}
@@ -68,7 +107,7 @@ func (p *Post) ReadPost(c *gin.Context) {
return
}
- rsp := response.GetPostResponse{
+ rsp := GetPostResponse{
CreatedAt: post.CreatedAt.Format("2006-01-02 15:04"),
TUuid: post.TUuid,
UuId: post.Uuid,
@@ -77,51 +116,102 @@ func (p *Post) ReadPost(c *gin.Context) {
Body: post.Body,
Exist: strconv.FormatBool(exist),
}
- response.FailMsgData(c, "获取回复成功", rsp)
+ OkMsgData(c, "获取回复成功", rsp)
return
}
+// DestroyPost 删除回复
+// @Summary 用户删除回复接口
+// @Description 用户删除回复接口
+// @Tags Post
+// @Accept json
+// @Produce json
+// @Param pUuid query string true "回复id"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} MessageResponse "删除成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/post/destroyPost [post]
func (p *Post) DestroyPost(c *gin.Context) {
//定义一个寻找到帖子请求的结构体
- req := &request.FindPostReq{}
+ req := &request2.FindPostReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
err := postService.DestroyPost(req.PUuid)
if err != nil {
- response.FailMsg(c, fmt.Sprintf("%v", err))
+ FailMsg(c, fmt.Sprintf("%v", err))
return
}
- response.FailMsg(c, "删除回复成功")
+ OkMsg(c, "删除回复成功")
return
}
+// GetPosts 获取该帖子的回复
+// @Summary 获取该帖子的回复接口
+// @Description 获取该帖子的回复接口
+// @Tags Post
+// @Accept json
+// @Produce json
+// @Param tUuid query string true "帖子id"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} []GetPostResponse "回复数据"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/post/getPosts [post]
func (p *Post) GetPosts(c *gin.Context) {
-
//定义一个获取回复请求的结构体
- req := &request.GetPostsReq{}
+ req := &request2.GetPostsReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
-
+ //从缓存中优先获取
+ cache, err := redis.GetResp("posts" + req.TUuid)
+ if err == nil {
+ var rsp []GetPostResponse
+ //解析缓存为对应格式
+ if err := json.Unmarshal(cache, &rsp); err == nil {
+ go func() {
+ for i, post := range rsp {
+ //存储前10个帖子的回复到缓存
+ if i < 10 {
+ owner := "reposts" + post.PUuid
+ exist, err := redis.ExistResp(owner)
+ if exist != 1 && err == nil {
+ lock1.Lock()
+ // 创建 Kafka 实例
+ topics := []string{"cache"}
+ group := "cache-group"
+ key := "reposts"
+ k := kafka.NewKafka(topics, group, key)
+ k.CreateCacheProducer(owner)
+ lock1.Unlock()
+ }
+ }
+ }
+ }()
+ OkMsgData(c, "从缓存中获取回复成功", rsp)
+ return
+ }
+ }
+ var rsp []GetPostResponse
//获取回复
posts, err := postService.GetPosts(req.TUuid)
if err != nil {
- response.FailMsgData(c, fmt.Sprintf("%v", err), models.Post{})
+ FailMsgData(c, fmt.Sprintf("%v", err), models.Post{})
return
}
- var rsp []response.GetPostResponse
- for _, post := range posts {
- p := response.GetPostResponse{
+ for i, post := range posts {
+ p := GetPostResponse{
CreatedAt: post.CreatedAt.Format("2006-01-02 15:04"),
TUuid: post.TUuid,
UuId: post.Uuid,
@@ -129,19 +219,48 @@ func (p *Post) GetPosts(c *gin.Context) {
Likes: post.Likes,
Body: post.Body,
}
+ //存储前10个帖子的回复到缓存
+ if i < 10 {
+ go func() {
+ owner := "reposts" + post.PUuid
+ exist, err := redis.ExistResp(owner)
+ if exist != 1 && err == nil {
+ lock1.Lock()
+ // 创建 Kafka 实例
+ topics := []string{"cache"}
+ group := "cache-group"
+ key := "reposts"
+ k := kafka.NewKafka(topics, group, key)
+ k.CreateCacheProducer(owner)
+ lock1.Unlock()
+ }
+ }()
+ }
rsp = append(rsp, p)
}
- response.FailMsgData(c, "获取回复成功", rsp)
+ OkMsgData(c, "获取回复成功", rsp)
return
}
+// LikePost 点赞/取消点赞回复
+// @Summary 点赞/取消点赞回复接口
+// @Description 用户点赞/取消点赞回复接口
+// @Tags Post
+// @Accept json
+// @Produce json
+// @Param uid query string true "这里对应的就是pUuid,但是方便你复制粘贴,帖子唯一标识"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} LikesResponse "点赞状态切换成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/post/likePost [post]
func (p *Post) LikePost(c *gin.Context) {
//定义一个创建帖子请求的结构体
- req := &request.LikesReq{}
+ req := &request2.LikesReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
@@ -151,10 +270,10 @@ func (p *Post) LikePost(c *gin.Context) {
//切换点赞状态
exist, err := postService.LikePosts(req.Uid, uuid)
if err != nil {
- response.FailMsgData(c, fmt.Sprintf("点赞切换失败:%v", err), response.LikesResponse{})
+ FailMsgData(c, fmt.Sprintf("点赞切换失败:%v", err), LikesResponse{})
return
}
- response.OkMsgData(c, fmt.Sprintf("点赞状态切换成功!"), response.LikesResponse{Exist: strconv.FormatBool(exist)})
+ OkMsgData(c, fmt.Sprintf("点赞状态切换成功!"), LikesResponse{Exist: strconv.FormatBool(exist)})
return
}
diff --git a/2024-Insomnia-Backend/app/controller/repost.go b/2024-Insomnia-Backend/app/controller/repost.go
index b0b0057..bc460c1 100644
--- a/2024-Insomnia-Backend/app/controller/repost.go
+++ b/2024-Insomnia-Backend/app/controller/repost.go
@@ -1,10 +1,13 @@
package controller
import (
+ . "Insomnia/app/api/request"
+ . "Insomnia/app/api/response"
+ . "Insomnia/app/infrastructure/helper"
+ "Insomnia/app/infrastructure/redis"
"Insomnia/app/models"
- "Insomnia/app/request"
- "Insomnia/app/response"
"Insomnia/app/service"
+ "encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
@@ -14,13 +17,27 @@ type RePost struct{}
var repostService *service.RePostService
+// CreateRePost 创建re回复
+// @Summary 用户创建re回复
+// @Description 用户创建re回复接口
+// @Tags RePost
+// @Accept json
+// @Produce json
+// @Param tUuid query string true "帖子id"
+// @Param pUuid query string true "回复id"
+// @Param body query string true "re回复内容"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} GetRePostResponse "re回复创建成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/rePost/createRePost [post]
func (r *RePost) CreateRePost(c *gin.Context) {
//定义一个创建帖子请求的结构体
- req := &request.CreateRePostReq{}
+ req := &CreateRePostReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
@@ -28,11 +45,11 @@ func (r *RePost) CreateRePost(c *gin.Context) {
uuid := Uuid.(string)
repost, err := repostService.CreateRePost(uuid, *req)
if err != nil {
- response.FailMsgData(c, fmt.Sprintf("创建re回复失败: %v", err), models.RePost{})
+ FailMsgData(c, fmt.Sprintf("创建re回复失败: %v", err), models.RePost{})
return
}
- rsp := response.GetRePostResponse{
+ rsp := GetRePostResponse{
CreatedAt: repost.CreatedAt.Format("2006-01-02 15:04"),
TUuid: repost.TUuid,
UuId: repost.Uuid,
@@ -41,23 +58,58 @@ func (r *RePost) CreateRePost(c *gin.Context) {
Body: repost.Body,
RUuid: repost.RUuid,
}
- response.FailMsgData(c, "创建回复成功", rsp)
+ err = redis.DelResp(repost.TUuid)
+ if err != nil {
+ Danger(err, "删除对应post缓存数据失败")
+ }
+ OkMsgData(c, "创建回复成功", rsp)
return
}
+// ReadRePost 创建re回复
+// @Summary 用户创建re回复
+// @Description 用户创建re回复接口
+// @Tags RePost
+// @Accept json
+// @Produce json
+// @Param rUuid query string true "re回复id"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} GetRePostResponse "re回复获取成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/rePost/readRePost [post]
func (r *RePost) ReadRePost(c *gin.Context) {
//定义一个寻找到帖子请求的结构体
- req := &request.FindRePostReq{}
+ req := &FindRePostReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
+ //从缓存中优先获取
+ cache, err := redis.GetResp(req.RUuid)
+ if err == nil {
+ rsp := GetRePostResponse{}
+ //解析缓存为对应格式
+ if err := json.Unmarshal(cache, &rsp); err == nil {
+ //获取点赞状态
+ Uuid, _ := c.Get("Uuid")
+ uuid := Uuid.(string)
+ exist, err := models.CheckLike(rsp.RUuid, uuid)
+ if err == nil {
+ rsp.Exist = strconv.FormatBool(exist)
+ OkMsgData(c, "从缓存中获取回复成功", rsp)
+ return
+ }
+ }
+ }
+
+ //未命中正常获取
repost, err := repostService.ReadRePost(req.RUuid)
if err != nil {
- response.FailMsgData(c, fmt.Sprintf("获取re回复失败: %v", err), models.Post{})
+ FailMsgData(c, fmt.Sprintf("获取re回复失败: %v", err), models.Post{})
return
}
@@ -69,7 +121,7 @@ func (r *RePost) ReadRePost(c *gin.Context) {
return
}
- rsp := response.GetRePostResponse{
+ rsp := GetRePostResponse{
CreatedAt: repost.CreatedAt.Format("2006-01-02 15:04"),
TUuid: repost.TUuid,
UuId: repost.Uuid,
@@ -79,51 +131,76 @@ func (r *RePost) ReadRePost(c *gin.Context) {
Body: repost.Body,
Exist: strconv.FormatBool(exist),
}
- response.FailMsgData(c, "获取re回复成功", rsp)
+
+ OkMsgData(c, "获取re回复成功", rsp)
return
}
+// DestroyRePost 删除re回复
+// @Summary 用户删除re回复
+// @Description 用户删除re回复接口
+// @Tags RePost
+// @Accept json
+// @Produce json
+// @Param rUuid query string true "re回复id"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} MessageResponse "re回复删除成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/rePost/destroyRePost [post]
func (r *RePost) DestroyRePost(c *gin.Context) {
//定义一个寻找到帖子请求的结构体
- req := &request.FindRePostReq{}
+ req := &FindRePostReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
err := repostService.DestroyRePost(req.RUuid)
if err != nil {
- response.FailMsg(c, fmt.Sprintf("%v", err))
+ FailMsg(c, fmt.Sprintf("%v", err))
return
}
- response.FailMsg(c, "删除re回复成功")
+ OkMsg(c, "删除re回复成功")
return
}
+// GetRePosts 获取指定回复下的re回复
+// @Summary 用户获取指定回复下的re回复
+// @Description 用户获取指定回复下的re回复接口
+// @Tags RePost
+// @Accept json
+// @Produce json
+// @Param pUuid query string true "回复id"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} GetRePostResponse "re回复获取成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/rePost/getRePosts [post]
func (r *RePost) GetRePosts(c *gin.Context) {
//定义一个获取回复请求的结构体
- req := &request.GetRePostsReq{}
+ req := &GetRePostsReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
//获取回复
reposts, err := repostService.GetRePosts(req.PUuid)
if err != nil {
- response.FailMsgData(c, fmt.Sprintf("%v", err), models.RePost{})
+ FailMsgData(c, fmt.Sprintf("%v", err), models.RePost{})
return
}
- var rsp []response.GetRePostResponse
+ var rsp []GetRePostResponse
for _, repost := range reposts {
- rp := response.GetRePostResponse{
+ rp := GetRePostResponse{
CreatedAt: repost.CreatedAt.Format("2006-01-02 15:04"),
TUuid: repost.TUuid,
UuId: repost.Uuid,
@@ -135,16 +212,28 @@ func (r *RePost) GetRePosts(c *gin.Context) {
rsp = append(rsp, rp)
}
- response.FailMsgData(c, "获取re回复成功", rsp)
+ OkMsgData(c, "获取re回复成功", rsp)
return
}
+// LikeRePost 获取指定回复下的re回复
+// @Summary 用户获取指定回复下的re回复
+// @Description 用户获取指定回复下的re回复接口
+// @Tags RePost
+// @Accept json
+// @Produce json
+// @Param uid query string true "这里对应的就是rUuid,但是方便你复制粘贴,帖子唯一标识"
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} LikesResponse "点赞状态切换成功"
+// @Failure 400 {object} ErrorResponse "请求参数错误"
+// @Failure 500 {object} ErrorResponse "内部错误"
+// @Router /api/v1/rePost/likeRePost [post]
func (r *RePost) LikeRePost(c *gin.Context) {
//定义一个创建帖子请求的结构体
- req := &request.LikesReq{}
+ req := &LikesReq{}
//使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
if err := c.ShouldBind(req); err != nil {
- response.FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
@@ -154,10 +243,10 @@ func (r *RePost) LikeRePost(c *gin.Context) {
//切换点赞状态
exist, err := repostService.LikeRePosts(req.Uid, uuid)
if err != nil {
- response.FailMsgData(c, fmt.Sprintf("点赞切换失败:%v", err), response.LikesResponse{})
+ FailMsgData(c, fmt.Sprintf("点赞切换失败:%v", err), LikesResponse{})
return
}
- response.FailMsgData(c, fmt.Sprintf("点赞状态切换成功!"), response.LikesResponse{Exist: strconv.FormatBool(exist)})
+ OkMsgData(c, fmt.Sprintf("点赞状态切换成功!"), LikesResponse{Exist: strconv.FormatBool(exist)})
return
}
diff --git a/2024-Insomnia-Backend/app/controller/task.go b/2024-Insomnia-Backend/app/controller/task.go
index d809920..66551a4 100644
--- a/2024-Insomnia-Backend/app/controller/task.go
+++ b/2024-Insomnia-Backend/app/controller/task.go
@@ -1,9 +1,11 @@
package controller
import (
- . "Insomnia/app/core/helper"
- "Insomnia/app/response"
+ "Insomnia/app/api/request"
+ . "Insomnia/app/api/response"
+ . "Insomnia/app/infrastructure/helper"
"Insomnia/app/service"
+ "fmt"
"github.com/gin-gonic/gin"
)
@@ -11,33 +13,52 @@ type Task struct{}
var taskService *service.TaskService
-func (t *Task) GetTask(c *gin.Context) {
+// UpTask 更新今日数据(星期),将今日完成的个数加一
+// @Summary 更新数据
+// @Description 更新数据
+// @Tags Task
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} GetMyDataResponse "更新数据成功"
+// @Failure 400 {object} string "请求参数错误"
+// @Failure 500 {object} string "内部错误"
+// @Router /api/v1/task/upTask [post]
+func (t *Task) UpTask(c *gin.Context) {
//获取当前用户的Uuid
Uuid, _ := c.Get("Uuid")
uuid := Uuid.(string)
- err, task := taskService.GetTask(uuid)
- if err != nil {
- response.FailMsgData(c, err.Error(), response.GetTaskResponse{})
+ //定义一个Login请求类型的结构体
+ req := &request.UpdateTaskNumber{}
+
+ //使用ShouldBind去解析获得的结构体,蛙趣真清晰啊
+ if err := c.ShouldBind(req); err != nil {
+ Danger(err, "解析请求结构体失败")
+ FailMsg(c, fmt.Sprintf("params invalid error: %v", err))
return
}
- todayTask := response.GetTaskResponse{Sum: task.Sum, Day: uint(task.Day)}
- response.OkMsgData(c, "获取今日数据成功", todayTask)
- return
-}
-func (t *Task) UpTask(c *gin.Context) {
- //获取当前用户的Uuid
- Uuid, _ := c.Get("Uuid")
- uuid := Uuid.(string)
- err := taskService.UpTask(uuid)
+ err := taskService.UpTask(uuid, req.Num)
if err != nil {
- response.FailMsg(c, err.Error())
+ FailMsg(c, err.Error())
return
}
- response.FailMsg(c, "更新数据成功!")
+
+ OkMsg(c, "更新数据成功!")
return
}
+// GetAllTask 获取本周数据(星期)
+// @Summary 获取数据
+// @Description 获取数据
+// @Tags Task
+// @Accept json
+// @Produce json
+// @Param Authorization header string true "jwt验证"
+// @Success 200 {object} []GetTaskResponse "获取数据成功"
+// @Failure 400 {object} string "请求参数错误"
+// @Failure 500 {object} string "内部错误"
+// @Router /api/v1/task/getAllTask [post]
func (t *Task) GetAllTask(c *gin.Context) {
//获取当前用户的Uuid
Uuid, _ := c.Get("Uuid")
@@ -45,9 +66,9 @@ func (t *Task) GetAllTask(c *gin.Context) {
err, allTask := taskService.GetAllTask(uuid)
if err != nil {
Danger(err, "获取本周数据失败")
- response.FailMsgData(c, err.Error(), []response.GetAllTaskResponse{})
+ FailMsgData(c, err.Error(), []int{})
return
}
- response.OkMsgData(c, "获取本周数据成功", allTask)
+ OkMsgData(c, "获取本周数据成功", allTask)
return
}
diff --git a/2024-Insomnia-Backend/app/controller/thread.go b/2024-Insomnia-Backend/app/controller/thread.go
index 193522b..0f689e3 100644
--- a/2024-Insomnia-Backend/app/controller/thread.go
+++ b/2024-Insomnia-Backend/app/controller/thread.go
@@ -1,19 +1,23 @@
package controller
import (
+ . "Insomnia/app/api/request"
+ . "Insomnia/app/api/response"
+ "Insomnia/app/infrastructure/kafka"
+ "Insomnia/app/infrastructure/redis"
"Insomnia/app/models"
- . "Insomnia/app/request"
- . "Insomnia/app/response"
"Insomnia/app/service"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"log"
"strconv"
+ "sync"
)
type Thread struct{}
+var lock sync.Mutex
var threadService *service.ThreadService
// CreateThread 创建帖子
@@ -22,10 +26,10 @@ var threadService *service.ThreadService
// @Tags Thread
// @Accept json
// @Produce json
-// @Param title body string true "标题"
-// @Param topic body string true "主题"
-// @Param body body string true "内容"
-// @Param images body []string true "图片链接列表"
+// @Param title query string true "标题"
+// @Param topic query string true "主题"
+// @Param body query string true "内容"
+// @Param images query []string true "图片链接列表"
// @Param Authorization header string true "jwt验证"
// @Success 200 {object} GetThreadResponse "帖子创建成功"
// @Failure 400 {object} ErrorResponse "请求参数错误"
@@ -65,7 +69,7 @@ func (t *Thread) CreateThread(c *gin.Context) {
Number: thread.Number,
Images: retrievedSlice,
}
- FailMsgData(c, "创建帖子成功", rsp)
+ OkMsgData(c, "创建帖子成功", rsp)
return
}
@@ -75,7 +79,7 @@ func (t *Thread) CreateThread(c *gin.Context) {
// @Tags Thread
// @Accept json
// @Produce json
-// @Param tUuid body string true "帖子唯一标识"
+// @Param tUuid query string true "帖子唯一标识"
// @Param Authorization header string true "jwt验证"
// @Success 200 {object} GetThreadResponse "获取帖子成功"
// @Failure 400 {object} ErrorResponse "请求参数错误"
@@ -123,6 +127,7 @@ func (t *Thread) ReadThread(c *gin.Context) {
Images: retrievedSlice,
Exist: strconv.FormatBool(exist),
}
+
OkMsgData(c, "获取帖子成功", rsp)
return
}
@@ -133,7 +138,7 @@ func (t *Thread) ReadThread(c *gin.Context) {
// @Tags Thread
// @Accept json
// @Produce json
-// @Param tUuid body string true "帖子唯一标识"
+// @Param tUuid query string true "帖子唯一标识"
// @Param Authorization header string true "jwt验证"
// @Success 200 {string} string "删除帖子成功"
// @Failure 400 {object} ErrorResponse "请求参数错误"
@@ -165,14 +170,13 @@ func (t *Thread) DestroyThread(c *gin.Context) {
// @Tags Thread
// @Accept json
// @Produce json
-// @Param topic body string true "主题"
+// @Param topic query string true "主题"
// @Param Authorization header string true "jwt验证"
// @Success 200 {object} []GetThreadResponse "获取帖子成功"
// @Failure 400 {object} ErrorResponse "请求参数错误"
// @Failure 500 {object} ErrorResponse "内部错误"
// @Router /api/v1/thread/getThreads [post]
func (t *Thread) GetThreads(c *gin.Context) {
-
//定义一个获取帖子请求的结构体
req := &GetThreadsReq{}
@@ -190,7 +194,7 @@ func (t *Thread) GetThreads(c *gin.Context) {
}
var rsp []GetThreadResponse
- for _, thread := range threads {
+ for i, thread := range threads {
threads := GetThreadResponse{
CreatedAt: thread.CreatedAt.Format("2006-01-02 15:04"),
TUuid: thread.TUuid,
@@ -201,10 +205,26 @@ func (t *Thread) GetThreads(c *gin.Context) {
Body: thread.Body,
Number: thread.Number,
}
+
+ //存储前10个帖子的回复到缓存
+ if i < 10 {
+ go func() {
+ owner := thread.TUuid
+ exist, err := redis.ExistResp("posts" + owner)
+ if exist != 1 && err == nil {
+ // 创建 Kafka 实例
+ topics := []string{"cache"}
+ group := "cache-group"
+ key := "posts"
+ k := kafka.NewKafka(topics, group, key)
+ k.CreateCacheProducer(owner)
+ }
+ }()
+ }
rsp = append(rsp, threads)
}
- FailMsgData(c, "获取帖子成功", rsp)
+ OkMsgData(c, "获取帖子成功", rsp)
return
}
@@ -245,7 +265,7 @@ func (t *Thread) GetMyThreads(c *gin.Context) {
rsp = append(rsp, threads)
}
- FailMsgData(c, "获取帖子成功", rsp)
+ OkMsgData(c, "获取帖子成功", rsp)
return
}
@@ -255,7 +275,7 @@ func (t *Thread) GetMyThreads(c *gin.Context) {
// @Tags Thread
// @Accept json
// @Produce json
-// @Param uid body string true "这里对应的就是tUuid,但是方便你复制粘贴,帖子唯一标识"
+// @Param uid query string true "这里对应的就是tUuid,但是方便你复制粘贴,帖子唯一标识"
// @Param Authorization header string true "jwt验证"
// @Success 200 {object} LikesResponse "点赞状态切换成功"
// @Failure 400 {object} ErrorResponse "请求参数错误"
@@ -280,6 +300,6 @@ func (t *Thread) LikeThread(c *gin.Context) {
return
}
- FailMsgData(c, fmt.Sprintf("点赞状态切换成功!"), LikesResponse{Exist: strconv.FormatBool(exist)})
+ OkMsgData(c, fmt.Sprintf("点赞状态切换成功!"), LikesResponse{Exist: strconv.FormatBool(exist)})
return
}
diff --git a/2024-Insomnia-Backend/app/controller/tube.go b/2024-Insomnia-Backend/app/controller/tube.go
index 624dfb9..3ca3d93 100644
--- a/2024-Insomnia-Backend/app/controller/tube.go
+++ b/2024-Insomnia-Backend/app/controller/tube.go
@@ -1,17 +1,17 @@
package controller
import (
- "Insomnia/app/common/tube"
- "Insomnia/app/response"
+ "Insomnia/app/api/response"
+ "Insomnia/app/utility/tube"
"github.com/gin-gonic/gin"
)
type Tube struct{}
type Token struct {
- token string
+ Token string `json:"token"`
}
func (t *Tube) GetQNToken(c *gin.Context) {
- response.OkData(c, Token{tube.GetQNToken()})
+ response.OkMsgData(c, "获取token成功", Token{Token: tube.GetQNToken()})
return
}
diff --git a/2024-Insomnia-Backend/app/models/email.go b/2024-Insomnia-Backend/app/infrastructure/Email/email.go
similarity index 81%
rename from 2024-Insomnia-Backend/app/models/email.go
rename to 2024-Insomnia-Backend/app/infrastructure/Email/email.go
index 7bea51f..9a8ab13 100644
--- a/2024-Insomnia-Backend/app/models/email.go
+++ b/2024-Insomnia-Backend/app/infrastructure/Email/email.go
@@ -1,7 +1,8 @@
-package models
+package Email
import (
- . "Insomnia/app/common/tool"
+ "Insomnia/app/infrastructure/redis"
+ . "Insomnia/app/utility/tool"
"context"
"errors"
"time"
@@ -21,7 +22,7 @@ func (email CheckEmail) CreateRedis() (err error) {
//限制时间为5分钟
expiration := 5 * time.Minute
//设施一个redis
- err = rdb.Set(ctx, key, email.VerificationCode, expiration).Err()
+ err = redis.Rdb.Set(ctx, key, email.VerificationCode, expiration).Err()
if err != nil {
return
}
@@ -34,7 +35,7 @@ func (email CheckEmail) CheckVerificationCode() (err error) {
// 在 Redis 中检查验证码
ctx := context.Background()
key := "verification_code:" + email.Email
- storedCode, err := rdb.Get(ctx, key).Result()
+ storedCode, err := redis.Rdb.Get(ctx, key).Result()
if err != nil {
return err
}
diff --git a/2024-Insomnia-Backend/app/core/config/config.go b/2024-Insomnia-Backend/app/infrastructure/config/config.go
similarity index 93%
rename from 2024-Insomnia-Backend/app/core/config/config.go
rename to 2024-Insomnia-Backend/app/infrastructure/config/config.go
index 4eea301..41c23a3 100644
--- a/2024-Insomnia-Backend/app/core/config/config.go
+++ b/2024-Insomnia-Backend/app/infrastructure/config/config.go
@@ -46,10 +46,10 @@ type Configuration struct {
}
type Oss struct {
- AccessKey string
- SecretKey string
- BucketName string
- DomainName string
+ AccessKey string
+ SecretKey string
+ Bucket string
+ Domain string
}
type JWT struct {
diff --git a/2024-Insomnia-Backend/app/core/helper/helper.go b/2024-Insomnia-Backend/app/infrastructure/helper/helper.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/core/helper/helper.go
rename to 2024-Insomnia-Backend/app/infrastructure/helper/helper.go
diff --git a/2024-Insomnia-Backend/app/common/jwt/jwt.go b/2024-Insomnia-Backend/app/infrastructure/jwt/jwt.go
similarity index 97%
rename from 2024-Insomnia-Backend/app/common/jwt/jwt.go
rename to 2024-Insomnia-Backend/app/infrastructure/jwt/jwt.go
index fc74812..e0bb013 100644
--- a/2024-Insomnia-Backend/app/common/jwt/jwt.go
+++ b/2024-Insomnia-Backend/app/infrastructure/jwt/jwt.go
@@ -1,7 +1,7 @@
package jwt
import (
- . "Insomnia/app/core/config"
+ . "Insomnia/app/infrastructure/config"
"fmt"
"github.com/golang-jwt/jwt/v4"
"time"
diff --git a/2024-Insomnia-Backend/app/infrastructure/kafka/kafka.go b/2024-Insomnia-Backend/app/infrastructure/kafka/kafka.go
new file mode 100644
index 0000000..df29d09
--- /dev/null
+++ b/2024-Insomnia-Backend/app/infrastructure/kafka/kafka.go
@@ -0,0 +1,256 @@
+package kafka
+
+import (
+ . "Insomnia/app/infrastructure/helper"
+ "Insomnia/app/infrastructure/redis"
+ "Insomnia/app/service"
+ "context"
+ "encoding/json"
+ "fmt"
+ "github.com/IBM/sarama"
+ log "github.com/sirupsen/logrus"
+ "sync"
+)
+
+type Kafka struct {
+ brokers []string
+ topics []string
+ startOffset int64
+ version string
+ ready chan bool
+ group string
+ channelBufferSize int
+ assignor string
+ key string
+}
+
+var brokers = []string{"localhost:9092"}
+var assignor = "range"
+
+func NewKafka(topics []string, group string, key string) *Kafka {
+ return &Kafka{
+ brokers: brokers,
+ topics: topics,
+ group: group,
+ channelBufferSize: 1000,
+ ready: make(chan bool),
+ version: "2.8.0",
+ assignor: assignor,
+ key: key,
+ }
+}
+
+// CreateCacheProducer key表示要发送的对象(缓存的对象),num表示要缓存的指定帖子页数
+func (k *Kafka) CreateCacheProducer(uid string) {
+ // 设置 Kafka 生产者的配置
+ config := sarama.NewConfig()
+ config.Producer.RequiredAcks = sarama.NoResponse
+ config.Producer.Retry.Max = 3
+ config.Producer.Return.Successes = true
+
+ // 创建 Kafka 生产者
+ producer, err := sarama.NewSyncProducer(k.brokers, config)
+ if err != nil {
+ log.Fatalf("Error creating producer: %v", err)
+ }
+ defer producer.Close()
+
+ //创建消息
+ message := &sarama.ProducerMessage{
+ Topic: "cache",
+ Key: sarama.StringEncoder(k.key),
+ Value: sarama.StringEncoder(uid),
+ }
+
+ partition, offset, err := producer.SendMessage(message)
+ if err != nil {
+ log.Fatalf("Error sending message: %v", err)
+ }
+
+ log.Printf("Message sent to partition %d at offset %d\n", partition, offset)
+}
+
+func (k *Kafka) CreateConsumerToGroup() func() {
+ log.Infoln("kafka init...")
+ //解析卡夫卡的版本
+ version, err := sarama.ParseKafkaVersion(k.version)
+ if err != nil {
+ log.Fatalf("Error parsing Kafka version: %v", err)
+ }
+ //初始化配置
+ config := sarama.NewConfig()
+ config.Version = version
+
+ // 分区分配策略
+ switch assignor {
+ case "sticky":
+ config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategySticky()}
+ case "roundrobin":
+ config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategyRoundRobin()}
+ case "range":
+ config.Consumer.Group.Rebalance.GroupStrategies = []sarama.BalanceStrategy{sarama.NewBalanceStrategyRange()}
+ default:
+ log.Panicf("Unrecognized consumer group partition assignor: %s", assignor)
+ }
+
+ //读取措施为从最早的开始
+ config.Consumer.Offsets.Initial = sarama.OffsetOldest
+ //设置消费者组的channel容量,即一次最多读取几个
+ config.ChannelBufferSize = k.channelBufferSize // channel长度
+
+ // 创建client
+ newClient, err := sarama.NewClient(brokers, config)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ // 获取所有的topic,似乎没什么意义
+ //topics, err := newClient.Topics()
+ //if err != nil {
+ // log.Fatal(err)
+ //}
+ //log.Info("topics: ", topics)
+
+ // 根据client和kafka指定的组别创建consumerGroup
+ client, err := sarama.NewConsumerGroupFromClient(k.group, newClient)
+ if err != nil {
+ log.Fatalf("Error creating consumer group client: %v", err)
+ }
+
+ //用于控制goroutine,不是很懂但是用的蛮多的
+ ctx, cancel := context.WithCancel(context.Background())
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ //死循环获取消息
+ for {
+ //消费者setup失败
+ if err := client.Consume(ctx, k.topics, k); err != nil {
+ // 当setup失败的时候,error会返回到这里
+ log.Errorf("Error from consumer: %v", err)
+ return
+ }
+ //检查ctx是否出错,一点也不懂
+ if ctx.Err() != nil {
+ log.Println(ctx.Err())
+ return
+ }
+ //把卡夫卡的ready状态清除
+ k.ready = make(chan bool)
+ }
+ }()
+ //如果k.ready接受到消息的话就执行
+ <-k.ready
+ log.Infoln("Sarama consumer up and running!...")
+ // 保证在系统退出时,通道里面的消息被消费
+ return func() {
+ log.Info("kafka close")
+ cancel()
+ wg.Wait()
+ if err = client.Close(); err != nil {
+ log.Errorf("Error closing client: %v", err)
+ }
+ }
+}
+
+func (k *Kafka) Setup(sarama.ConsumerGroupSession) error {
+ log.Info("setup")
+ return nil
+}
+
+func (k *Kafka) Cleanup(sarama.ConsumerGroupSession) error {
+ log.Info("cleanup")
+ return nil
+}
+
+func (k *Kafka) ConsumeClaim(session sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error {
+ batchSize := 10 // 定义每次处理的消息数量
+ //定义一个用于临时存储消息数据的
+ messages := make([]*sarama.ConsumerMessage, 0, batchSize)
+
+ for {
+ select {
+ case <-session.Context().Done():
+ return nil
+ default:
+ // 尝试从claim.Messages()中获取消息,直到达到批量处理阈值或者没有更多消息
+ for i := 0; i < batchSize; i++ {
+ select {
+ case message, ok := <-claim.Messages():
+ if !ok {
+ break
+ }
+ messages = append(messages, message)
+ case <-session.Context().Done():
+ return nil
+ }
+ }
+
+ // 处理批量消息
+ for _, message := range messages {
+ exist, err := redis.ExistResp(string(message.Value))
+ if exist != 1 && err == nil {
+ if string(message.Key) == "posts" {
+ p := &service.PostService{}
+ posts, err := p.GetPosts(string(message.Value))
+ if err != nil {
+ Danger(err, "加载缓存时取时获取post数据失败")
+ }
+ jsonString, err := json.Marshal(posts)
+ if err != nil {
+ Danger(err, "格式转换失败")
+ }
+ err = redis.SetResp(string(message.Key)+string(message.Value), jsonString)
+ if err != nil {
+ Danger(err, "加载缓存时存储数据失败")
+ }
+ fmt.Println("posts缓存存储成功")
+ } else if string(message.Key) == "reposts" {
+ p := &service.RePostService{}
+ reposts, err := p.GetRePosts(string(message.Value))
+ if err != nil {
+ Danger(err, "加载缓存时取时获取repost数据失败")
+ }
+ jsonString, err := json.Marshal(reposts)
+ if err != nil {
+ Danger(err, "格式转换失败")
+ }
+ err = redis.SetResp(string(message.Key)+string(message.Value), jsonString)
+ if err != nil {
+ Danger(err, "加载缓存时取时存储数据失败")
+ }
+ fmt.Println("reposts缓存存储成功")
+ }
+ }
+ session.MarkMessage(message, "")
+ }
+ // 清空消息列表
+ messages = messages[:0]
+ }
+ }
+}
+
+// 启动消费者组
+func (k *Kafka) Consume(ctx context.Context, consumerGroup sarama.ConsumerGroup) {
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
+
+ go func() {
+ defer wg.Done()
+ for {
+ select {
+ case <-ctx.Done():
+ return
+ default:
+ if err := consumerGroup.Consume(ctx, k.topics, k); err != nil {
+ log.Errorf("Error from consumer: %v", err)
+ return
+ }
+ }
+ }
+ }()
+
+ <-ctx.Done()
+ wg.Wait()
+}
diff --git a/2024-Insomnia-Backend/app/core/middlewares/auth.go b/2024-Insomnia-Backend/app/infrastructure/middlewares/auth.go
similarity index 85%
rename from 2024-Insomnia-Backend/app/core/middlewares/auth.go
rename to 2024-Insomnia-Backend/app/infrastructure/middlewares/auth.go
index b509ce4..b2e5b54 100644
--- a/2024-Insomnia-Backend/app/core/middlewares/auth.go
+++ b/2024-Insomnia-Backend/app/infrastructure/middlewares/auth.go
@@ -1,8 +1,8 @@
package middlewares
import (
- "Insomnia/app/common/jwt"
- "Insomnia/app/response"
+ "Insomnia/app/api/response"
+ "Insomnia/app/infrastructure/jwt"
"github.com/gin-gonic/gin"
)
diff --git a/2024-Insomnia-Backend/app/core/middlewares/cors.go b/2024-Insomnia-Backend/app/infrastructure/middlewares/cors.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/core/middlewares/cors.go
rename to 2024-Insomnia-Backend/app/infrastructure/middlewares/cors.go
diff --git a/2024-Insomnia-Backend/app/core/middlewares/middlewares.go b/2024-Insomnia-Backend/app/infrastructure/middlewares/middlewares.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/core/middlewares/middlewares.go
rename to 2024-Insomnia-Backend/app/infrastructure/middlewares/middlewares.go
diff --git a/2024-Insomnia-Backend/app/core/middlewares/recovery.go b/2024-Insomnia-Backend/app/infrastructure/middlewares/recovery.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/core/middlewares/recovery.go
rename to 2024-Insomnia-Backend/app/infrastructure/middlewares/recovery.go
diff --git a/2024-Insomnia-Backend/app/models/redis.go b/2024-Insomnia-Backend/app/infrastructure/redis/redis.go
similarity index 56%
rename from 2024-Insomnia-Backend/app/models/redis.go
rename to 2024-Insomnia-Backend/app/infrastructure/redis/redis.go
index 5b74f52..7d01863 100644
--- a/2024-Insomnia-Backend/app/models/redis.go
+++ b/2024-Insomnia-Backend/app/infrastructure/redis/redis.go
@@ -1,14 +1,15 @@
-package models
+package redis
import (
- . "Insomnia/app/core/config"
+ . "Insomnia/app/infrastructure/config"
"context"
"fmt"
"github.com/go-redis/redis/v8"
"os/exec"
+ "time"
)
-var rdb *redis.Client
+var Rdb *redis.Client
func init() {
// 检查 Redis 服务器是否已经运行
@@ -27,12 +28,13 @@ func init() {
fmt.Println("Redis server started.")
config := LoadConfig()
//初始化Redis客户端
- rdb = redis.NewClient(&redis.Options{
+ Rdb = redis.NewClient(&redis.Options{
Addr: config.Re.Address,
Password: config.Re.Password,
DB: config.Re.Database,
})
}
+
}
// 检查 Redis 服务器是否已经运行
@@ -44,14 +46,17 @@ func isRedisRunning() (bool, error) {
Password: config.Re.Password,
DB: config.Re.Database,
})
- defer client.Close()
+
_, err := client.Ping(ctx).Result()
if err == nil {
+ Rdb = client
return true, nil
}
+ defer client.Close()
if err.Error() == "redis: can't connect to the server" {
return false, err
}
+
return false, nil
}
@@ -64,3 +69,36 @@ func startRedisServer() error {
}
return nil
}
+
+// SetResp 设置redis里面的结果
+func SetResp(owner string, value any) error {
+ return Rdb.Set(context.Background(), owner, value, 1*time.Hour).Err()
+}
+
+// SetNXResp 如果没设置过的话就设置
+func SetNXResp(owner string, value any) error {
+ return Rdb.SetNX(context.Background(), owner, value, 1*time.Hour).Err()
+}
+
+// ExistResp 检查是否已经存储
+func ExistResp(owner string) (exist int64, err error) {
+ exist, err = Rdb.Exists(context.Background(), owner).Result()
+ return
+}
+
+// DelResp 删除对应的缓存
+func DelResp(owner string) error {
+ return Rdb.Del(context.Background(), owner).Err()
+}
+
+func GetResp(owner string) ([]byte, error) {
+ get := Rdb.Get(context.Background(), owner)
+ if get.Err() != nil {
+ return nil, get.Err()
+ }
+ bytes, err := get.Bytes()
+ if err != nil {
+ return nil, err
+ }
+ return bytes, nil
+}
diff --git a/2024-Insomnia-Backend/app/models/db.go b/2024-Insomnia-Backend/app/models/db.go
index 50ab92e..c27249e 100644
--- a/2024-Insomnia-Backend/app/models/db.go
+++ b/2024-Insomnia-Backend/app/models/db.go
@@ -1,8 +1,8 @@
package models
import (
- "Insomnia/app/common/tube"
- . "Insomnia/app/core/config"
+ . "Insomnia/app/infrastructure/config"
+ "Insomnia/app/utility/tube"
"fmt"
"gorm.io/driver/mysql"
_ "gorm.io/driver/mysql"
diff --git a/2024-Insomnia-Backend/app/models/post.go b/2024-Insomnia-Backend/app/models/post.go
index 4d63c8f..bfbb13f 100644
--- a/2024-Insomnia-Backend/app/models/post.go
+++ b/2024-Insomnia-Backend/app/models/post.go
@@ -1,8 +1,8 @@
package models
import (
- . "Insomnia/app/common/tool"
- "Insomnia/app/request"
+ "Insomnia/app/api/request"
+ . "Insomnia/app/utility/tool"
"gorm.io/gorm"
)
diff --git a/2024-Insomnia-Backend/app/models/repost.go b/2024-Insomnia-Backend/app/models/repost.go
index 24d8f47..a6e30f4 100644
--- a/2024-Insomnia-Backend/app/models/repost.go
+++ b/2024-Insomnia-Backend/app/models/repost.go
@@ -1,8 +1,8 @@
package models
import (
- . "Insomnia/app/common/tool"
- "Insomnia/app/request"
+ "Insomnia/app/api/request"
+ . "Insomnia/app/utility/tool"
"gorm.io/gorm"
)
diff --git a/2024-Insomnia-Backend/app/models/tasks.go b/2024-Insomnia-Backend/app/models/tasks.go
index 9f0e7c6..48b654d 100644
--- a/2024-Insomnia-Backend/app/models/tasks.go
+++ b/2024-Insomnia-Backend/app/models/tasks.go
@@ -8,26 +8,41 @@ import (
// Task 个人总数据
type Task struct {
gorm.Model
- Uuid string `gorm:"size:64;not null;unique"`
- Sum uint
- Day int `gorm:"not null"`
+ Uuid string
+ Monday uint
+ Tuesday uint
+ Wednesday uint
+ Thursday uint
+ Friday uint
+ Saturday uint
+ Sunday uint
}
-// Update 方法更新数据+1
-func (task Task) Update() (err error) {
- task.Sum += 1
- result := Db.Model(task).Update("sum", task.Sum)
- if result.Error != nil {
- err = result.Error
- return
+//Day := []string{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}
+
+// Update 方法更新数据
+func (task Task) Update(num uint) (err error) {
+
+ //获取当前时间
+ currentTime := time.Now()
+ switch int(currentTime.Weekday()) {
+ case 0:
+ task.Sunday = num
+ case 1:
+ task.Monday = num
+ case 2:
+ task.Tuesday = num
+ case 3:
+ task.Wednesday = num
+ case 4:
+ task.Thursday = num
+ case 5:
+ task.Friday = num
+ case 6:
+ task.Saturday = num
}
- return
-}
-// GetAllTaskByUuid 方法获取所有的task数据
-func GetAllTaskByUuid(uuid string) (task []Task, err error) {
- //根据email查询用户记录
- result := Db.Where("uuid = ?", uuid).First(&task)
+ result := Db.Model(task).Table("tasks").Where("uuid =?", task.Uuid).Save(&task)
if result.Error != nil {
err = result.Error
return
@@ -35,25 +50,28 @@ func GetAllTaskByUuid(uuid string) (task []Task, err error) {
return
}
-// GetTaskByUuid 方法获取当天的数据,不存在会自动创建
-func GetTaskByUuid(uuid string) (task Task, err error) {
- //获取当前时间
- currentTime := time.Now()
- // 获取当天的起始时间和结束时间
- startOfDay := currentTime.Truncate(24 * time.Hour)
- endOfDay := startOfDay.Add(24 * time.Hour)
-
- // 根据uuid和时间范围查询任务记录
- result := Db.Where("uuid = ? AND created_at >= ? AND created_at < ?", uuid, startOfDay, endOfDay).First(&task)
+// GetAllTaskByUuid 方法获取所有的task数据
+func GetAllTaskByUuid(uuid string) (task *Task, err error) {
+ // 根据uuid查询任务记录
+ result := Db.Where("uuid = ?", uuid).First(&task)
if result.Error != nil {
- // 如果记录不存在,创建新的任务记录
- task.CreatedAt = currentTime
- task.Sum = 0
+ task.Sunday = 0
+ task.Monday = 0
+ task.Tuesday = 0
+ task.Wednesday = 0
+ task.Thursday = 0
+ task.Friday = 0
+ task.Saturday = 0
task.Uuid = uuid
- task.Day = int(currentTime.Weekday())
+
result = Db.Create(&task)
+ if result.Error != nil {
+ err = result.Error
+ return
+ }
+ result = Db.Where("uuid = ?", uuid).First(&task)
if result.Error != nil {
err = result.Error
return
@@ -62,15 +80,3 @@ func GetTaskByUuid(uuid string) (task Task, err error) {
return
}
-
-// DestroyOldByUuid 方法摧毁用户这周之前的所有任务数据
-func DestroyOldByUuid(uuid string) {
- // 获取当前时间
- currentTime := time.Now()
-
- // 计算当前日期所在的周的起始日期(周一为一周的起始)
- startOfWeek := currentTime.AddDate(0, 0, -int(currentTime.Weekday())+1).Truncate(24 * time.Hour)
-
- // 根据uuid和时间范围删除任务记录
- Db.Where("uuid = ? AND created_at < ?", uuid, startOfWeek).Delete(&Task{})
-}
diff --git a/2024-Insomnia-Backend/app/models/thread.go b/2024-Insomnia-Backend/app/models/thread.go
index 266f36c..b388c35 100644
--- a/2024-Insomnia-Backend/app/models/thread.go
+++ b/2024-Insomnia-Backend/app/models/thread.go
@@ -1,8 +1,8 @@
package models
import (
- . "Insomnia/app/common/tool"
- "Insomnia/app/request"
+ "Insomnia/app/api/request"
+ . "Insomnia/app/utility/tool"
"encoding/json"
"gorm.io/gorm"
"log"
diff --git a/2024-Insomnia-Backend/app/models/user.go b/2024-Insomnia-Backend/app/models/user.go
index fe857ce..4234976 100644
--- a/2024-Insomnia-Backend/app/models/user.go
+++ b/2024-Insomnia-Backend/app/models/user.go
@@ -1,7 +1,7 @@
package models
import (
- . "Insomnia/app/common/tool"
+ . "Insomnia/app/utility/tool"
"gorm.io/gorm"
)
diff --git a/2024-Insomnia-Backend/app/service/auth.go b/2024-Insomnia-Backend/app/service/auth.go
index 141ca19..46bf97c 100644
--- a/2024-Insomnia-Backend/app/service/auth.go
+++ b/2024-Insomnia-Backend/app/service/auth.go
@@ -1,11 +1,12 @@
package service
import (
- "Insomnia/app/common/jwt"
- "Insomnia/app/common/tool"
+ . "Insomnia/app/api/request"
+ . "Insomnia/app/api/response"
+ "Insomnia/app/infrastructure/Email"
+ "Insomnia/app/infrastructure/jwt"
"Insomnia/app/models"
- . "Insomnia/app/request"
- . "Insomnia/app/response"
+ "Insomnia/app/utility/tool"
"fmt"
)
@@ -14,7 +15,7 @@ type AuthService struct{}
// Signup 注册新用户
func (a *AuthService) Signup(signup SignupReq) (err error) {
//获取用户信息
- eck := models.CheckEmail{
+ eck := Email.CheckEmail{
Email: signup.Email,
VerificationCode: signup.VerificationCode,
}
@@ -63,7 +64,7 @@ func (a *AuthService) Login(email string, password string) (string, error) {
// ChangePassword 更新密码
func (a *AuthService) ChangePassword(cp ChangePasswordReq) (err error) {
//获取用户信息
- eck := models.CheckEmail{
+ eck := Email.CheckEmail{
Email: cp.Email,
VerificationCode: cp.VerificationCode,
}
diff --git a/2024-Insomnia-Backend/app/service/myMessage.go b/2024-Insomnia-Backend/app/service/myMessage.go
index 9af8662..4968177 100644
--- a/2024-Insomnia-Backend/app/service/myMessage.go
+++ b/2024-Insomnia-Backend/app/service/myMessage.go
@@ -1,8 +1,8 @@
package service
import (
+ . "Insomnia/app/api/request"
"Insomnia/app/models"
- . "Insomnia/app/request"
)
type MyMessageService struct{}
diff --git a/2024-Insomnia-Backend/app/service/post.go b/2024-Insomnia-Backend/app/service/post.go
index ab619eb..2b05e01 100644
--- a/2024-Insomnia-Backend/app/service/post.go
+++ b/2024-Insomnia-Backend/app/service/post.go
@@ -1,8 +1,8 @@
package service
import (
+ . "Insomnia/app/api/request"
"Insomnia/app/models"
- . "Insomnia/app/request"
"fmt"
)
diff --git a/2024-Insomnia-Backend/app/service/repost.go b/2024-Insomnia-Backend/app/service/repost.go
index 57e8376..ce69bf4 100644
--- a/2024-Insomnia-Backend/app/service/repost.go
+++ b/2024-Insomnia-Backend/app/service/repost.go
@@ -1,8 +1,8 @@
package service
import (
+ . "Insomnia/app/api/request"
"Insomnia/app/models"
- . "Insomnia/app/request"
"fmt"
)
diff --git a/2024-Insomnia-Backend/app/service/task.go b/2024-Insomnia-Backend/app/service/task.go
index 0f9122b..e39fd3e 100644
--- a/2024-Insomnia-Backend/app/service/task.go
+++ b/2024-Insomnia-Backend/app/service/task.go
@@ -1,9 +1,7 @@
package service
import (
- "Insomnia/app/models"
. "Insomnia/app/models"
- "Insomnia/app/response"
"fmt"
)
@@ -11,16 +9,16 @@ type TaskService struct{}
// UpTask /POST /task1/upTask
// 更新任务数据
-func (t *TaskService) UpTask(uuid string) (err error) {
+func (t *TaskService) UpTask(uuid string, num uint) (err error) {
- //获取当月任务数据
- task, err := GetTaskByUuid(uuid)
+ //获取当日任务数据
+ task, err := GetAllTaskByUuid(uuid)
if err != nil {
return fmt.Errorf("用户任务数据查询错误:%v", err)
}
//更新任务数据
- err = task.Update()
+ err = task.Update(num)
if err != nil {
return fmt.Errorf("用户任务数据更新失败%v", err)
}
@@ -28,44 +26,23 @@ func (t *TaskService) UpTask(uuid string) (err error) {
return nil
}
-// GetTask /GET /task1/getTask
-// 获取本日任务数据
-func (t *TaskService) GetTask(uuid string) (error, models.Task) {
-
- //删除用户所有这周之前的任务数据
- DestroyOldByUuid(uuid)
-
- //获取本日的任务数据
- task, err := GetTaskByUuid(uuid)
- if err != nil {
- return fmt.Errorf("用户任务数据查询错误%v", err), models.Task{}
- }
-
- return nil, task
-}
-
// GetAllTask /GET /task1/getAllTask
// 获取本周的数据
-func (t *TaskService) GetAllTask(uuid string) (error, []response.GetAllTaskResponse) {
- //删除用户所有这周之前的任务数据
- DestroyOldByUuid(uuid)
- var allTask []response.GetAllTaskResponse
- var t4 response.GetAllTaskResponse
- var t1 response.GetTaskResponse
- var t2 []response.GetTaskResponse
+func (t *TaskService) GetAllTask(uuid string) (error, []uint) {
+ tasks := make([]uint, 7)
+
//获取本周的任务数据
task, err := GetAllTaskByUuid(uuid)
if err != nil {
- return fmt.Errorf("用户任务数据查询错误:%v", err), []response.GetAllTaskResponse{}
+ return fmt.Errorf("用户任务数据查询错误:%v", err), tasks
}
- for _, t3 := range task {
- t1 = response.GetTaskResponse{
- Sum: t3.Sum,
- Day: uint(t3.Day),
- }
- t2 = append(t2, t1)
- t4 = response.GetAllTaskResponse{AllTask: t2}
- allTask = append(allTask, t4)
- }
- return nil, allTask
+
+ tasks[0] = task.Monday
+ tasks[1] = task.Tuesday
+ tasks[2] = task.Wednesday
+ tasks[3] = task.Thursday
+ tasks[4] = task.Friday
+ tasks[5] = task.Saturday
+ tasks[6] = task.Sunday
+ return nil, tasks
}
diff --git a/2024-Insomnia-Backend/app/service/thread.go b/2024-Insomnia-Backend/app/service/thread.go
index 294d7bc..118a0cc 100644
--- a/2024-Insomnia-Backend/app/service/thread.go
+++ b/2024-Insomnia-Backend/app/service/thread.go
@@ -1,8 +1,8 @@
package service
import (
+ . "Insomnia/app/api/request"
"Insomnia/app/models"
- . "Insomnia/app/request"
"fmt"
)
diff --git a/2024-Insomnia-Backend/app/common/tool/tool.go b/2024-Insomnia-Backend/app/utility/tool/tool.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/common/tool/tool.go
rename to 2024-Insomnia-Backend/app/utility/tool/tool.go
diff --git a/2024-Insomnia-Backend/app/common/tube/tube.go b/2024-Insomnia-Backend/app/utility/tube/tube.go
similarity index 87%
rename from 2024-Insomnia-Backend/app/common/tube/tube.go
rename to 2024-Insomnia-Backend/app/utility/tube/tube.go
index 8b9c05b..7eadd2c 100644
--- a/2024-Insomnia-Backend/app/common/tube/tube.go
+++ b/2024-Insomnia-Backend/app/utility/tube/tube.go
@@ -1,7 +1,7 @@
package tube
import (
- . "Insomnia/app/core/config"
+ . "Insomnia/app/infrastructure/config"
"context"
"github.com/qiniu/go-sdk/v7/auth/qbox"
"github.com/qiniu/go-sdk/v7/storage"
@@ -25,8 +25,8 @@ func LoadQiniu() {
Q = Qiniu{
AccessKey: c.Oss.AccessKey,
SecretKey: c.Oss.SecretKey,
- Bucket: c.Oss.BucketName,
- Domain: c.Oss.DomainName,
+ Bucket: c.Oss.Bucket,
+ Domain: c.Oss.Domain,
}
}
@@ -40,10 +40,12 @@ func UploadFileToQiniu(localFilePath string) (string, error) {
}
//将cfg解析成对应格式上传
uploader := storage.NewFormUploader(&cfg)
+
//put政策的规定
putPolicy := storage.PutPolicy{
Scope: Q.Bucket,
}
+
//将token解析成对应格式上传
token := putPolicy.UploadToken(mac)
@@ -65,18 +67,14 @@ func UploadFileToQiniu(localFilePath string) (string, error) {
}
func GetQNToken() string {
- //左移32位,得到2**32是要干嘛?
- var maxInt uint64 = 1 << 32
+
+ mac := qbox.NewMac(Q.AccessKey, Q.SecretKey)
//put政策的规定
putPolicy := storage.PutPolicy{
- Scope: Q.Bucket,
- Expires: maxInt,
+ Scope: Q.Bucket,
}
- //token
- mac := qbox.NewMac(Q.AccessKey, Q.SecretKey)
-
//将token转化为对应格式
QNToken := putPolicy.UploadToken(mac)
return QNToken
diff --git a/2024-Insomnia-Backend/app/common/xerr/xerr.go b/2024-Insomnia-Backend/app/utility/xerr/xerr.go
similarity index 100%
rename from 2024-Insomnia-Backend/app/common/xerr/xerr.go
rename to 2024-Insomnia-Backend/app/utility/xerr/xerr.go
diff --git a/2024-Insomnia-Backend/dump.rdb b/2024-Insomnia-Backend/dump.rdb
deleted file mode 100644
index 57943fc..0000000
Binary files a/2024-Insomnia-Backend/dump.rdb and /dev/null differ
diff --git a/2024-Insomnia-Backend/go.mod b/2024-Insomnia-Backend/go.mod
index 878f922..c8e7279 100644
--- a/2024-Insomnia-Backend/go.mod
+++ b/2024-Insomnia-Backend/go.mod
@@ -3,25 +3,28 @@ module Insomnia
go 1.22.0
require (
+ github.com/IBM/sarama v1.43.2
github.com/gin-gonic/gin v1.9.1
github.com/go-redis/redis/v8 v8.11.5
github.com/golang-jwt/jwt/v4 v4.5.0
- github.com/gookit/config/v2 v2.2.5
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
github.com/qiniu/go-sdk/v7 v7.19.0
+ github.com/sirupsen/logrus v1.9.3
github.com/swaggo/swag v1.16.2
- go.uber.org/zap v1.26.0
gorm.io/driver/mysql v1.5.2
gorm.io/gorm v1.25.7
)
require (
- dario.cat/mergo v1.0.0 // indirect
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
+ github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
+ github.com/eapache/go-resiliency v1.6.0 // indirect
+ github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
+ github.com/eapache/queue v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
@@ -33,31 +36,37 @@ require (
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
- github.com/gookit/color v1.5.4 // indirect
- github.com/gookit/goutil v0.6.15 // indirect
- github.com/gorilla/websocket v1.5.1 // indirect
+ github.com/golang/snappy v0.0.4 // indirect
+ github.com/google/go-cmp v0.5.9 // indirect
+ github.com/hashicorp/errwrap v1.0.0 // indirect
+ github.com/hashicorp/go-multierror v1.1.1 // indirect
+ github.com/hashicorp/go-uuid v1.0.3 // indirect
+ github.com/jcmturner/aescts/v2 v2.0.0 // indirect
+ github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
+ github.com/jcmturner/gofork v1.7.6 // indirect
+ github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
+ github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
+ github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
- github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
+ github.com/pierrec/lz4/v4 v4.1.21 // indirect
+ github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
- github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
- go.uber.org/multierr v1.10.0 // indirect
golang.org/x/arch v0.3.0 // indirect
- golang.org/x/crypto v0.18.0 // indirect
- golang.org/x/net v0.20.0 // indirect
- golang.org/x/sync v0.6.0 // indirect
- golang.org/x/sys v0.16.0 // indirect
- golang.org/x/term v0.16.0 // indirect
+ golang.org/x/crypto v0.22.0 // indirect
+ golang.org/x/net v0.24.0 // indirect
+ golang.org/x/sync v0.7.0 // indirect
+ golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
diff --git a/2024-Insomnia-Backend/go.sum b/2024-Insomnia-Backend/go.sum
index b13706c..a29b97e 100644
--- a/2024-Insomnia-Backend/go.sum
+++ b/2024-Insomnia-Backend/go.sum
@@ -1,5 +1,5 @@
-dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
-dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
+github.com/IBM/sarama v1.43.2 h1:HABeEqRUh32z8yzY2hGB/j8mHSzC/HA9zlEjqFNCzSw=
+github.com/IBM/sarama v1.43.2/go.mod h1:Kyo4WkF24Z+1nz7xeVUFWIuKVV8RS3wM8mkvPKMdXFQ=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
@@ -16,8 +16,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
-github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
-github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
+github.com/eapache/go-resiliency v1.6.0 h1:CqGDTLtpwuWKn6Nj3uNUdflaq+/kIPsg0gfNzHton30=
+github.com/eapache/go-resiliency v1.6.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
+github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 h1:Oy0F4ALJ04o5Qqpdz8XLIpNA3WM/iSIXqxtqo7UGVws=
+github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3/go.mod h1:YvSRo5mw33fLEx1+DlK6L2VV43tJt5Eyel9n9XBcR+0=
+github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
+github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
+github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
+github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
@@ -55,25 +61,36 @@ github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrt
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
-github.com/goccy/go-yaml v1.11.2 h1:joq77SxuyIs9zzxEjgyLBugMQ9NEgTWxXfz2wVqwAaQ=
-github.com/goccy/go-yaml v1.11.2/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
+github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
-github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0=
-github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w=
-github.com/gookit/config/v2 v2.2.5 h1:RECbYYbtherywmzn3LNeu9NA5ZqhD7MSKEMsJ7l+MpU=
-github.com/gookit/config/v2 v2.2.5/go.mod h1:NeX+yiNYn6Ei10eJvCQFXuHEPIE/IPS8bqaFIsszzaM=
-github.com/gookit/goutil v0.6.15 h1:mMQ0ElojNZoyPD0eVROk5QXJPh2uKR4g06slgPDF5Jo=
-github.com/gookit/goutil v0.6.15/go.mod h1:qdKdYEHQdEtyH+4fNdQNZfJHhI0jUZzHxQVAV3DaMDY=
-github.com/gookit/ini/v2 v2.2.3 h1:nSbN+x9OfQPcMObTFP+XuHt8ev6ndv/fWWqxFhPMu2E=
-github.com/gookit/ini/v2 v2.2.3/go.mod h1:Vu6p7P7xcfmb8KYu3L0ek8bqu/Im63N81q208SCCZY4=
-github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
-github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
+github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
+github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
+github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
+github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
+github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
+github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
+github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
+github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
+github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
+github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
+github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
+github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
+github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
+github.com/jcmturner/gofork v1.7.6 h1:QH0l3hzAU1tfT3rZCnW5zXl+orbkNMMRGJfdJjHVETg=
+github.com/jcmturner/gofork v1.7.6/go.mod h1:1622LH6i/EZqLloHfE7IeZ0uEJwMSUyQ/nDd82IeqRo=
+github.com/jcmturner/goidentity/v6 v6.0.1 h1:VKnZd2oEIMorCTsFBnJWbExfNN7yZr3EhJAxwOkZg6o=
+github.com/jcmturner/goidentity/v6 v6.0.1/go.mod h1:X1YW3bgtvwAXju7V3LCIMpY0Gbxyjn/mY9zx4tFonSg=
+github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh687T8=
+github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs=
+github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY=
+github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@@ -84,6 +101,8 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
+github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
+github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
@@ -101,12 +120,8 @@ github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
-github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
-github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
-github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@@ -120,6 +135,8 @@ github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
+github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=
+github.com/pierrec/lz4/v4 v4.1.21/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -127,14 +144,19 @@ github.com/qiniu/dyn v1.3.0/go.mod h1:E8oERcm8TtwJiZvkQPbcAh0RL8jO1G0VXJMW3FAWdk
github.com/qiniu/go-sdk/v7 v7.19.0 h1:k3AzDPil8QHIQnki6xXt4YRAjE52oRoBUXQ4bV+Wc5U=
github.com/qiniu/go-sdk/v7 v7.19.0/go.mod h1:nqoYCNo53ZlGA521RvRethvxUDvXKt4gtYXOwye868w=
github.com/qiniu/x v1.10.5/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
+github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
+github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
+github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
+github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -142,23 +164,15 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
-github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
-github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
+github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
+github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/swaggo/swag v1.16.2 h1:28Pp+8DkQoV+HLzLx8RGJZXNGKbFqnuvSbAAtoxiY04=
github.com/swaggo/swag v1.16.2/go.mod h1:6YzXnDcpr0767iOejs318CwYkCQqyGer6BizOg03f+E=
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/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
-github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
-go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
-go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
-go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
-go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
-go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
-go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
@@ -166,45 +180,49 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
-golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
-golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
-golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 h1:MDc5xs78ZrZr3HMQugiXOAkSZtfTpbJLDr/lwfgO53E=
-golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
+golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
+golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
+golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
-golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
-golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
+golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
+golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
+golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
+golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/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.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
-golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
+golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
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=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
-golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
+golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
-golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
-golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
+golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
+golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -214,8 +232,6 @@ golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
-golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
@@ -226,6 +242,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
@@ -235,8 +252,6 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.5.2 h1:QC2HRskSE75wBuOxe0+iCkyJZ+RqpudsQtqkp+IMuXs=
gorm.io/driver/mysql v1.5.2/go.mod h1:pQLhh1Ut/WUAySdTHwBpBv6+JKcj+ua4ZFx1QQTBzb8=
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
-gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
-gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
diff --git a/2024-Insomnia-Backend/main b/2024-Insomnia-Backend/main
deleted file mode 100644
index e218940..0000000
Binary files a/2024-Insomnia-Backend/main and /dev/null differ
diff --git a/2024-Insomnia-Backend/main.go b/2024-Insomnia-Backend/main.go
index d22e5b4..e883507 100644
--- a/2024-Insomnia-Backend/main.go
+++ b/2024-Insomnia-Backend/main.go
@@ -1,22 +1,16 @@
package main
import (
- "Insomnia/app/core/middlewares"
- "Insomnia/app/routers"
+ "Insomnia/app/api/routers"
+ "Insomnia/app/infrastructure/kafka"
+ "Insomnia/app/infrastructure/middlewares"
"github.com/gin-gonic/gin"
- "gorm.io/gorm"
"log"
+ "os"
+ "os/signal"
+ "syscall"
)
-// 个人总数据
-type taskSumData struct {
- gorm.Model
- Uuid string `gorm:"size:64;not null;unique"`
- Email string `gorm:"size:255;not null;unique"`
- Sum uint
- Tasks string
-}
-
// @title 不眠夜
// @version 1.0
// @description 一个匿名熬夜论坛
@@ -26,8 +20,26 @@ func main() {
routers.Load(engine)
//加载中间件
middlewares.Load(engine)
-
- if err := engine.Run("localhost:8080"); err != nil {
+ //加载消费者组
+ go ConsumerGroup()
+ if err := engine.Run(":8000"); err != nil {
log.Fatal(err)
}
}
+
+func ConsumerGroup() {
+ // 创建 Kafka 实例
+ topics := []string{"cache"}
+ group := "cache-group"
+ key := "cache-key"
+ kafkaClient := kafka.NewKafka(topics, group, key)
+
+ // 创建并启动消费者组
+ closeConsumer := kafkaClient.CreateConsumerToGroup()
+ defer closeConsumer()
+
+ // 监听信号以优雅地退出程序
+ sigterm := make(chan os.Signal, 1)
+ signal.Notify(sigterm, syscall.SIGINT, syscall.SIGTERM)
+ <-sigterm
+}
diff --git a/2024-Insomnia-Backend/temp-10912.rdb b/2024-Insomnia-Backend/temp-10912.rdb
deleted file mode 100644
index 9a436be..0000000
Binary files a/2024-Insomnia-Backend/temp-10912.rdb and /dev/null differ
diff --git a/2024-Insomnia-Backend/temp-14124.rdb b/2024-Insomnia-Backend/temp-14124.rdb
deleted file mode 100644
index 09751fa..0000000
Binary files a/2024-Insomnia-Backend/temp-14124.rdb and /dev/null differ
diff --git a/2024-Insomnia-Backend/temp-24068.rdb b/2024-Insomnia-Backend/temp-24068.rdb
deleted file mode 100644
index 7daf415..0000000
Binary files a/2024-Insomnia-Backend/temp-24068.rdb and /dev/null differ
diff --git a/2024-Insomnia-Backend/temp-27192.rdb b/2024-Insomnia-Backend/temp-27192.rdb
deleted file mode 100644
index 9141fa6..0000000
Binary files a/2024-Insomnia-Backend/temp-27192.rdb and /dev/null differ
diff --git a/2024-Insomnia-Backend/temp-29204.rdb b/2024-Insomnia-Backend/temp-29204.rdb
deleted file mode 100644
index e69de29..0000000