mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 15:32:26 +08:00
GM后台服务初步
This commit is contained in:
51
gm/controller/controller.go
Normal file
51
gm/controller/controller.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hk4e/common/config"
|
||||
"hk4e/logger"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
}
|
||||
|
||||
func NewController() (r *Controller) {
|
||||
r = new(Controller)
|
||||
go r.registerRouter()
|
||||
return r
|
||||
}
|
||||
|
||||
func (c *Controller) authorize() gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
if true {
|
||||
// 验证通过
|
||||
context.Next()
|
||||
return
|
||||
}
|
||||
// 验证不通过
|
||||
context.Abort()
|
||||
context.JSON(http.StatusOK, gin.H{
|
||||
"code": "10001",
|
||||
"msg": "没有访问权限",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) registerRouter() {
|
||||
if config.CONF.Logger.Level == "DEBUG" {
|
||||
gin.SetMode(gin.DebugMode)
|
||||
} else {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
}
|
||||
engine := gin.Default()
|
||||
engine.Use(c.authorize())
|
||||
engine.POST("/gm/cmd", c.gmCmd)
|
||||
port := config.CONF.HttpPort
|
||||
addr := ":" + strconv.Itoa(port)
|
||||
err := engine.Run(addr)
|
||||
if err != nil {
|
||||
logger.LOG.Error("gin run error: %v", err)
|
||||
}
|
||||
}
|
||||
20
gm/controller/gm_controller.go
Normal file
20
gm/controller/gm_controller.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hk4e/logger"
|
||||
)
|
||||
|
||||
type GmCmdReq struct {
|
||||
FuncName string `json:"func_name"`
|
||||
Param []string `json:"param"`
|
||||
}
|
||||
|
||||
func (c *Controller) gmCmd(context *gin.Context) {
|
||||
gmCmdReq := new(GmCmdReq)
|
||||
err := context.ShouldBindJSON(gmCmdReq)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
logger.LOG.Info("%v", gmCmdReq)
|
||||
}
|
||||
Reference in New Issue
Block a user