40 lines
953 B
Go
40 lines
953 B
Go
|
|
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
|
||
|
|
}
|
||
|
|
}
|