소스 검색

no message

panghu 8 달 전
부모
커밋
970347d5d9
1개의 변경된 파일과 34개의 추가작업 그리고 0개의 파일을 삭제
  1. 34 0
      api/base.go

+ 34 - 0
api/base.go

@@ -0,0 +1,34 @@
+package api
+
+import (
+	"github.com/gin-gonic/gin"
+	"net/http"
+)
+
+type BaseController struct {
+}
+
+// PageData 分页数据返回格式
+type pageData struct {
+	Limit      interface{} `json:"limit"` //  分页数量
+	Items      interface{} `json:"items"` //  数据列表
+	TotalCount int         `json:"total"` //  总数量
+}
+
+// ResponseSuccess 成功响应格式
+func (b BaseController) responseSuccess(c *gin.Context, data interface{}) {
+	c.JSON(http.StatusOK, gin.H{
+		"code":    0,
+		"message": "success",
+		"data":    data,
+	})
+}
+
+// ResponseError 错误响应格式
+func (b BaseController) responseError(c *gin.Context, code int, message string) {
+	c.JSON(http.StatusOK, gin.H{
+		"code":    code,
+		"message": message,
+		"data":    nil,
+	})
+}