initial crm server

This commit is contained in:
zchengo
2022-11-28 16:38:30 +08:00
parent 61122aef6a
commit af7cd0c44c
36 changed files with 2615 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
package response
const (
ErrCodeSuccess = 0 // 成功
ErrCodeFailed = 1 // 失败
ErrCodeParamInvalid = 2 // 请求参数无效
ErrCodeNoLogin = 3 // 未登录或非法访问
ErrCodeTokenExpire = 4 // Token过期
ErrCodeUserHasExist = 10001 // 用户已经存在
ErrCodeUserNotExist = 10002 // 用户不存在
ErrCOdeUserEmailOrPass = 10003 // 用户邮箱或密码错误
ErrCodeVerityCodeSendFailed = 10004 // 验证码发送失败
ErrCodeVerityCodeInvalid = 10005 // 验证码无效
ErrCodeCompanyCreateFailed = 10006 // 企业创建失败
ErrCodeCompanyIdNotExist = 10007 // 企业编号不存在
ErrCodeEmailFormatInvalid = 10008 // 邮箱格式无效
ErrCodeUserPassResetFailed = 10009 // 用户密码重置失败
)
var msg = map[int]string{
ErrCodeSuccess: "success",
ErrCodeFailed: "failed",
ErrCodeParamInvalid: "param invalid",
ErrCodeNoLogin: "no login",
ErrCodeTokenExpire: "token expire",
ErrCodeUserHasExist: "user has exist",
ErrCodeUserNotExist: "user not exist",
ErrCOdeUserEmailOrPass: "user email or password error",
ErrCodeVerityCodeSendFailed: "verify code send failed",
ErrCodeVerityCodeInvalid: "verify code invalid",
ErrCodeCompanyCreateFailed: "company create failed",
ErrCodeEmailFormatInvalid: "email format invalid",
ErrCodeUserPassResetFailed: "user password reset failed",
}
+31
View File
@@ -0,0 +1,31 @@
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
type Page struct {
Total int64 `json:"total"`
List interface{} `json:"list"`
}
// 响应结果
func Result(code int, data interface{}, c *gin.Context) {
message := msg[code]
c.JSON(http.StatusOK, Response{code, message, data})
}
// 响应分页结果
func PageResult(code int, data interface{}, rows int64, c *gin.Context) {
message := msg[code]
page := &Page{Total: rows, List: data}
c.JSON(http.StatusOK, Response{code, message, page})
}