From ee478c105fa0cf3a9406536f3292d64c332b1581 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Fri, 19 Jul 2024 09:43:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0tool=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/user.go | 2 ++ handler/tool.go | 39 +++++++++++++++++++++++++++++++++++++++ proto/status.go | 3 +++ 3 files changed, 44 insertions(+) create mode 100644 handler/tool.go diff --git a/dao/user.go b/dao/user.go index 5f171be..c5a2db9 100644 --- a/dao/user.go +++ b/dao/user.go @@ -14,6 +14,8 @@ type User struct { Password string `gorm:"column:password"` Gender string `gorm:"column:gender"` Role string `gorm:"column:role"` + Redis bool `gorm:"column:redis"` + Run bool `gorm:"column:run"` CreateTime string `gorm:"column:create_time"` UpdateTime string `gorm:"column:update_time"` } diff --git a/handler/tool.go b/handler/tool.go new file mode 100644 index 0000000..4d585de --- /dev/null +++ b/handler/tool.go @@ -0,0 +1,39 @@ +package handler + +import ( + "github.com/gin-gonic/gin" + "net/http" + "videoplayer/dao" + "videoplayer/proto" +) + +type SetRedisReq struct { + Option string `json:"option" form:"option"` + Key string `json:"key" form:"key"` + Value string `json:"value" form:"value"` + Expire int `json:"expire" form:"expire"` +} + +func SetUpToolGroup(router *gin.Engine) { + toolGroup := router.Group("/tool") + toolGroup.POST("/set_redis", SetRedis) +} + +func SetRedis(c *gin.Context) { + //先查看是否有权限 + id, _ := c.Get("id") + id1 := int(id.(float64)) + user := dao.FindUserByUserID(id1) + if user.Redis == false { + c.JSON(http.StatusOK, gin.H{"error": "no redis Permissions", "code": proto.NoRedisPermissions, "message": "failed"}) + return + } + //解析请求参数 + var req SetRedisReq + if err := c.ShouldBind(&req); err == nil { + + } else { + c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"}) + return + } +} diff --git a/proto/status.go b/proto/status.go index 51478e9..cc636b1 100644 --- a/proto/status.go +++ b/proto/status.go @@ -41,4 +41,7 @@ const ( // UUID相关错误码 UUIDNotFound = 18 // uuid不存在 + + //Tool + NoRedisPermissions = 51 )