feat 改名
This commit is contained in:
18
Server/gatewaytt/handler/http_handler/helper/base.go
Normal file
18
Server/gatewaytt/handler/http_handler/helper/base.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package helper
|
||||
|
||||
type Pagination struct {
|
||||
Page int `json:"page"` // 页
|
||||
Size int `json:"size"` // 页大小
|
||||
}
|
||||
|
||||
//func SetBaseQuery(page *Pagination, order string) func(db *gorm.DB) *gorm.DB {
|
||||
// return func(db *gorm.DB) *gorm.DB {
|
||||
// if page != nil {
|
||||
// db = db.Offset((page.Page - 1) * page.Size).Limit(page.Size)
|
||||
// }
|
||||
// if len(order) > 0 {
|
||||
// db = db.Order(order)
|
||||
// }
|
||||
// return db
|
||||
// }
|
||||
//}
|
||||
31
Server/gatewaytt/handler/http_handler/helper/render/code.go
Normal file
31
Server/gatewaytt/handler/http_handler/helper/render/code.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package render
|
||||
|
||||
var (
|
||||
OK = NewCode(0, "成功")
|
||||
Failed = NewCode(1, "失败")
|
||||
ParamError = NewCode(1001, "参数错误")
|
||||
NameEmpty = NewCode(1002, "名称不能为空")
|
||||
NameDuplicate = NewCode(1003, "名称或编号不能重复")
|
||||
ListEmpty = NewCode(1004, "列表不能为空")
|
||||
RepeatCommit = NewCode(1005, "请勿重复提交")
|
||||
)
|
||||
|
||||
type Code struct {
|
||||
code int
|
||||
message string
|
||||
}
|
||||
|
||||
func NewCode(code int, message string) *Code {
|
||||
return &Code{
|
||||
code: code,
|
||||
message: message,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Code) Code() int {
|
||||
return c.code
|
||||
}
|
||||
|
||||
func (c *Code) Message() string {
|
||||
return c.message
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package render
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type RespJsonData struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
func Json(c *gin.Context, code *Code, data interface{}) {
|
||||
result := &RespJsonData{
|
||||
Code: code.Code(),
|
||||
Msg: code.Message(),
|
||||
Data: data,
|
||||
}
|
||||
c.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
func JsonByStatus(c *gin.Context, status int, code *Code, data interface{}) {
|
||||
result := &RespJsonData{
|
||||
Code: code.Code(),
|
||||
Msg: code.Message(),
|
||||
Data: data,
|
||||
}
|
||||
c.JSON(status, result)
|
||||
}
|
||||
|
||||
func AbortJson(c *gin.Context, code *Code, data interface{}) {
|
||||
result := &RespJsonData{
|
||||
Code: code.Code(),
|
||||
Msg: code.Message(),
|
||||
Data: data,
|
||||
}
|
||||
c.AbortWithStatusJSON(http.StatusOK, result)
|
||||
}
|
||||
16
Server/gatewaytt/handler/http_handler/unique_id.go
Normal file
16
Server/gatewaytt/handler/http_handler/unique_id.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package http_handler
|
||||
|
||||
import (
|
||||
"common/utils"
|
||||
"gateway/handler/http_handler/helper/render"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type UniqueIDResp struct {
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
// GenSnowflake 生成雪花ID
|
||||
func GenSnowflake(c *gin.Context) {
|
||||
render.Json(c, render.OK, &UniqueIDResp{ID: utils.SnowflakeInstance().Generate().String()})
|
||||
}
|
||||
Reference in New Issue
Block a user