feat(foundation):构建基本的路由创建结构。

This commit is contained in:
徐涛
2022-08-09 15:22:25 +08:00
parent 35dc66f935
commit d614bcc8e1
3 changed files with 66 additions and 6 deletions

28
response/base-response.go Normal file
View File

@@ -0,0 +1,28 @@
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Result struct {
Ctx *gin.Context
}
type BaseResponse struct {
Code int `json:"code"`
Message string `json:"message"`
}
func NewResult(ctx *gin.Context) *Result {
return &Result{Ctx: ctx}
}
// 统一出错信息
func (r *Result) Error(code int, msg string) {
res := BaseResponse{}
res.Code = code
res.Message = msg
r.Ctx.JSON(http.StatusOK, res)
}