Compare commits
No commits in common. "16f397d507f296edf46afbc893f681b6a984c987" and "cd3c9a30cef3b70befaeb52824140ba9a2a45d18" have entirely different histories.
16f397d507
...
cd3c9a30ce
|
|
@ -14,8 +14,6 @@ type User struct {
|
||||||
Password string `gorm:"column:password"`
|
Password string `gorm:"column:password"`
|
||||||
Gender string `gorm:"column:gender"`
|
Gender string `gorm:"column:gender"`
|
||||||
Role string `gorm:"column:role"`
|
Role string `gorm:"column:role"`
|
||||||
Redis bool `gorm:"column:redis"`
|
|
||||||
Run bool `gorm:"column:run"`
|
|
||||||
CreateTime string `gorm:"column:create_time"`
|
CreateTime string `gorm:"column:create_time"`
|
||||||
UpdateTime string `gorm:"column:update_time"`
|
UpdateTime string `gorm:"column:update_time"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,17 +50,10 @@ func SetUpCIDGroup(router *gin.Engine) {
|
||||||
}
|
}
|
||||||
func RunCID(c *gin.Context) {
|
func RunCID(c *gin.Context) {
|
||||||
var req CIDRunReq
|
var req CIDRunReq
|
||||||
id, _ := c.Get("id")
|
|
||||||
authID := int(id.(float64))
|
|
||||||
//获取权限
|
|
||||||
user := dao.FindUserByUserID(authID)
|
|
||||||
if user.Run == false {
|
|
||||||
c.JSON(200, gin.H{"error": "no run Permissions", "code": proto.NoRunPermissions, "message": "no run Permissions"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := c.ShouldBind(&req); err == nil {
|
if err := c.ShouldBind(&req); err == nil {
|
||||||
// 获取用户ID
|
// 获取用户ID
|
||||||
|
id, _ := c.Get("id")
|
||||||
|
authID := int(id.(float64))
|
||||||
username, _ := c.Get("username")
|
username, _ := c.Get("username")
|
||||||
cid := dao.FindCIDByID(req.ID, authID)
|
cid := dao.FindCIDByID(req.ID, authID)
|
||||||
if cid.ID == 0 {
|
if cid.ID == 0 {
|
||||||
|
|
@ -172,18 +165,11 @@ func CIDCallback(c *gin.Context) {
|
||||||
fmt.Println("token:", token, "cid_id:", cid_id)
|
fmt.Println("token:", token, "cid_id:", cid_id)
|
||||||
//将cid转换为int
|
//将cid转换为int
|
||||||
cid, _ := strconv.Atoi(cid_id)
|
cid, _ := strconv.Atoi(cid_id)
|
||||||
|
|
||||||
if token == "" || cid == 0 {
|
if token == "" || cid == 0 {
|
||||||
c.JSON(200, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
c.JSON(200, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
res := dao.FindCIDByIDAndToken(cid, token)
|
res := dao.FindCIDByIDAndToken(cid, token)
|
||||||
|
|
||||||
user := dao.FindUserByUserID(res.Auth_id)
|
|
||||||
if user.Run == false {
|
|
||||||
c.JSON(200, gin.H{"error": "no run Permissions", "code": proto.NoRunPermissions, "message": "the user has no run Permissions"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if res.ID != 0 {
|
if res.ID != 0 {
|
||||||
user := dao.FindUserByID(res.Auth_id)
|
user := dao.FindUserByID(res.Auth_id)
|
||||||
go RunShell(user[0].Name, res.Url, res.Script, int(res.ID), res.Auth_id)
|
go RunShell(user[0].Name, res.Url, res.Script, int(res.ID), res.Auth_id)
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
package handler
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"net/http"
|
|
||||||
"videoplayer/dao"
|
|
||||||
"videoplayer/proto"
|
|
||||||
"videoplayer/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
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)
|
|
||||||
toolGroup.POST("/get_redis", GetRedis)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
var code int
|
|
||||||
var message string
|
|
||||||
if req.Option == "list" {
|
|
||||||
code, message = service.SetToolRedisList(req.Key, req.Value, req.Expire)
|
|
||||||
} else if req.Option == "set" {
|
|
||||||
code, message = service.SetToolRedisSet(req.Key, req.Value, req.Expire)
|
|
||||||
} else if req.Option == "kv" {
|
|
||||||
code, message = service.SetToolRedisKV(req.Key, req.Value, req.Expire)
|
|
||||||
}
|
|
||||||
c.JSON(http.StatusOK, gin.H{"code": code, "message": message})
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetRedis(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 {
|
|
||||||
code, message := service.GetToolRedis(req.Key)
|
|
||||||
req.Value = message
|
|
||||||
c.JSON(http.StatusOK, gin.H{"code": code, "message": message, "data": req})
|
|
||||||
} else {
|
|
||||||
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
3
main.go
3
main.go
|
|
@ -27,8 +27,7 @@ func main() {
|
||||||
handler.SetUpDeviceGroup(r) // Device
|
handler.SetUpDeviceGroup(r) // Device
|
||||||
handler.SetUpIMGroup(r) // IM
|
handler.SetUpIMGroup(r) // IM
|
||||||
handler.SetUpCIDGroup(r) // CID,持续集成、部署
|
handler.SetUpCIDGroup(r) // CID,持续集成、部署
|
||||||
handler.SetUpToolGroup(r) // Tool
|
r.Run(":8083") // listen and serve on 0.0.0.0:8082
|
||||||
r.Run(":8083") // listen and serve on 0.0.0.0:8083
|
|
||||||
defer dao.Close()
|
defer dao.Close()
|
||||||
defer worker.CloseRedis()
|
defer worker.CloseRedis()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,4 @@ const (
|
||||||
|
|
||||||
// UUID相关错误码
|
// UUID相关错误码
|
||||||
UUIDNotFound = 18 // uuid不存在
|
UUIDNotFound = 18 // uuid不存在
|
||||||
|
|
||||||
//Tool
|
|
||||||
NoRedisPermissions = 51
|
|
||||||
NoRunPermissions = 52
|
|
||||||
NoDevicePermissions = 53
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
"videoplayer/proto"
|
|
||||||
"videoplayer/worker"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetToolRedisList(key string, value string, expire int) (code int, message string) {
|
|
||||||
if expire == 0 {
|
|
||||||
if worker.PushRedisList(key, value) {
|
|
||||||
return proto.SuccessCode, "success"
|
|
||||||
} else {
|
|
||||||
return proto.OperationFailed, "push redis list failed"
|
|
||||||
}
|
|
||||||
} else if expire > 0 {
|
|
||||||
if worker.PushRedisListWithExpire(key, value, time.Duration(expire)) {
|
|
||||||
return proto.SuccessCode, "success"
|
|
||||||
} else {
|
|
||||||
return proto.OperationFailed, "push redis list with expire failed"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return proto.ParameterError, "expire time can not be negative"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetToolRedisSet(key string, value string, expire int) (code int, message string) {
|
|
||||||
if expire == 0 {
|
|
||||||
if worker.SetRedis(key, value) {
|
|
||||||
return proto.SuccessCode, "success"
|
|
||||||
} else {
|
|
||||||
return proto.OperationFailed, "set redis failed"
|
|
||||||
}
|
|
||||||
} else if expire > 0 {
|
|
||||||
if worker.SetRedisWithExpire(key, value, time.Duration(expire)) {
|
|
||||||
return proto.SuccessCode, "success"
|
|
||||||
} else {
|
|
||||||
return proto.OperationFailed, "set redis with expire failed"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return proto.ParameterError, "expire time can not be negative"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetToolRedisKV(key string, value string, expire int) (code int, message string) {
|
|
||||||
if expire == 0 {
|
|
||||||
if worker.SetRedis(key, value) {
|
|
||||||
return proto.SuccessCode, "success"
|
|
||||||
} else {
|
|
||||||
return proto.OperationFailed, "set redis failed"
|
|
||||||
}
|
|
||||||
} else if expire > 0 {
|
|
||||||
if worker.SetRedisWithExpire(key, value, time.Duration(expire)) {
|
|
||||||
return proto.SuccessCode, "success"
|
|
||||||
} else {
|
|
||||||
return proto.OperationFailed, "set redis with expire failed"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return proto.ParameterError, "expire time can not be negative"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetToolRedis(key string) (code int, message string) {
|
|
||||||
val := worker.GetRedis(key)
|
|
||||||
if val == "" {
|
|
||||||
return proto.OperationFailed, "get redis failed"
|
|
||||||
} else {
|
|
||||||
return proto.SuccessCode, val
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue