api 模板的修改
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
Name: home-user-auth
|
||||
Host: 0.0.0.0
|
||||
Port: 8888
|
||||
DataSource: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||
|
||||
SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||
|
||||
Auth:
|
||||
AccessSecret: fusen2023
|
||||
|
||||
@@ -8,6 +8,6 @@ import (
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
DataSource string
|
||||
Auth types.Auth
|
||||
SourceMysql string
|
||||
Auth types.Auth
|
||||
}
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewGetTypeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetType(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
resp := l.GetType(&req)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/user/get-type",
|
||||
Handler: GetTypeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/user/basic-info",
|
||||
Handler: UserSaveBasicInfoHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -1,29 +1,39 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"fusenapi/utils/auth"
|
||||
)
|
||||
|
||||
func UserBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewUserBasicInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UserBasicInfo(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
userinfo := auth.CheckAuth(r)
|
||||
resp := l.UserBasicInfo(&req, &userinfo)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func UserFontsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewUserFontsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UserFonts(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
resp := l.UserFonts(&req)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.RequestUserLogin
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewUserLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UserLogin(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
resp := l.UserLogin(&req)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
39
home-user-auth/internal/handler/usersavebasicinfohandler.go
Normal file
39
home-user-auth/internal/handler/usersavebasicinfohandler.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
)
|
||||
|
||||
func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.RequestBasicInfoForm
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewUserSaveBasicInfoLogic(r.Context(), svcCtx)
|
||||
userinfo := auth.CheckAuth(r)
|
||||
resp := l.UserSaveBasicInfo(&req, &userinfo)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/model"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -23,19 +25,16 @@ func NewGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTypeLo
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetTypeLogic) GetType(req *types.Request) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
data, err := l.svcCtx.FsCanteenTypeModel.FindGetType(l.ctx)
|
||||
func (l *GetTypeLogic) GetType(req *types.Request) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
|
||||
data, err := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
resp.SetStatus(basic.StatusOK, "success", data)
|
||||
|
||||
// logx.Info(f)
|
||||
resp = &types.Response{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: data,
|
||||
}
|
||||
return
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import (
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/model"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -23,9 +26,25 @@ func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Use
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
|
||||
// l.svcCtx.FsUserModel.FindOne(l.ctx, )
|
||||
return
|
||||
if userinfo.UserId == 0 {
|
||||
resp = &types.Response{
|
||||
Code: 510,
|
||||
Message: "user is not exists",
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
resp.Set(510, err.Error())
|
||||
return resp
|
||||
}
|
||||
|
||||
resp.SetStatus(basic.StatusOK, fsUserModel)
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/model"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -23,19 +25,18 @@ func NewUserFontsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFon
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserFontsLogic) UserFonts(req *types.Request) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
f, err := l.svcCtx.FsFontModel.FindAllOrderSortByDesc(l.ctx)
|
||||
func (l *UserFontsLogic) UserFonts(req *types.Request) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
|
||||
data, err := model.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
|
||||
if err != nil {
|
||||
// panic(err)
|
||||
logx.Error(err)
|
||||
return
|
||||
resp.SetStatus(basic.StatusOK, data)
|
||||
return resp
|
||||
}
|
||||
// logx.Info(f)
|
||||
resp = &types.Response{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: f,
|
||||
}
|
||||
return
|
||||
|
||||
resp.SetStatus(basic.StatusOK)
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -2,13 +2,12 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/model"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -26,37 +25,21 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserLoginLogic) getJwtToken(secretKey string, iat, seconds, userId int64) (string, error) {
|
||||
claims := make(jwt.MapClaims)
|
||||
claims["exp"] = iat + seconds
|
||||
claims["iat"] = iat
|
||||
claims["userId"] = userId
|
||||
token := jwt.New(jwt.SigningMethodHS256)
|
||||
token.Claims = claims
|
||||
return token.SignedString([]byte(secretKey))
|
||||
}
|
||||
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
|
||||
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
data, err := l.svcCtx.FsUserModel.FindOneByEmail(l.ctx, req.Name)
|
||||
// logx.Info(err.Error())
|
||||
log.Printf("%t %t %v", err, model.ErrNotFound, err == model.ErrNotFound)
|
||||
userModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOneByEmail(l.ctx, req.Name)
|
||||
|
||||
// log.Printf("%t %t %v", err, model.ErrNotFound, err == model.ErrNotFound)
|
||||
if err == model.ErrNotFound {
|
||||
// logx.Error(err)
|
||||
resp = &types.Response{
|
||||
Code: 304,
|
||||
Message: "fail",
|
||||
}
|
||||
return resp, nil
|
||||
logx.Error(err)
|
||||
resp.SetStatusWithMessage(basic.DefaultError, err.Error())
|
||||
return resp
|
||||
}
|
||||
|
||||
resp = &types.Response{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: &types.DataUserLogin{
|
||||
Token: data.PasswordResetToken.String,
|
||||
},
|
||||
data := &types.DataUserLogin{
|
||||
Token: userModel.PasswordResetToken.String,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
resp.SetStatus(basic.StatusOK, data)
|
||||
return resp
|
||||
}
|
||||
|
||||
45
home-user-auth/internal/logic/usersavebasicinfologic.go
Normal file
45
home-user-auth/internal/logic/usersavebasicinfologic.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"fusenapi/model"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserSaveBasicInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserSaveBasicInfoLogic {
|
||||
return &UserSaveBasicInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *types.Response) {
|
||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||
resp = &types.Response{}
|
||||
// logx.Info(req)
|
||||
if userinfo.UserId == 0 {
|
||||
resp.SetStatusWithMessage(basic.DefaultError, "user is not exists")
|
||||
return resp
|
||||
}
|
||||
|
||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
}
|
||||
|
||||
resp.SetStatus(basic.StatusOK, fsUserModel)
|
||||
return resp
|
||||
}
|
||||
@@ -2,24 +2,18 @@ package svc
|
||||
|
||||
import (
|
||||
"fusenapi/home-user-auth/internal/config"
|
||||
"fusenapi/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
FsFontModel model.FsFontModel
|
||||
FsCanteenTypeModel model.FsCanteenTypeModel
|
||||
FsUserModel model.FsUserModel
|
||||
Config config.Config
|
||||
|
||||
MysqlConn sqlx.SqlConn
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
conn := sqlx.NewMysql(c.DataSource)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
FsFontModel: model.NewFsFontModel(conn),
|
||||
FsCanteenTypeModel: model.NewFsCanteenTypeModel(conn),
|
||||
FsUserModel: model.NewFsUserModel(conn),
|
||||
Config: c,
|
||||
MysqlConn: sqlx.NewMysql(c.SourceMysql),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,30 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
import (
|
||||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
}
|
||||
|
||||
type RequestBasicInfoForm struct {
|
||||
FirstName string `form:"first_name,optional" db:"first_name"` // FirstName
|
||||
LastName string `form:"last_name,optional" db:"last_name"` // LastName
|
||||
Company string `form:"company,optional" db:"company"` // 公司名称
|
||||
Mobile string `form:"mobile,optional" db:"mobile"` // 手机号码
|
||||
Email string `form:"email" db:"email"` // 邮箱
|
||||
Status int64 `form:"status,optional" db:"status"` // 1正常 0不正常
|
||||
IsOrderStatusEmail int64 `form:"is_order_status_email,optional" db:"is_order_status_email"` // 订单状态改变时是否接收邮件
|
||||
IsEmailAdvertisement int64 `form:"is_email_advertisement,optional" db:"is_email_advertisement"` // 是否接收邮件广告
|
||||
IsOrderStatusPhone int64 `form:"is_order_status_phone,optional" db:"is_order_status_phone"` // 订单状态改变是是否接收电话
|
||||
IsPhoneAdvertisement int64 `form:"is_phone_advertisement,optional" db:"is_phone_advertisement"` // 是否接收短信广告
|
||||
IsOpenRender int64 `form:"is_open_render,optional" db:"is_open_render"` // 是否打开个性化渲染(1:开启,0:关闭)
|
||||
IsLowRendering int64 `form:"is_low_rendering,optional" db:"is_low_rendering"` // 是否开启低渲染模型渲染
|
||||
IsRemoveBg int64 `form:"is_remove_bg,optional" db:"is_remove_bg"` // 用户上传logo是否去除背景
|
||||
NewPassword string `form:"new_password,optional" db:"new_password"` // new_password 如果存在新密码
|
||||
}
|
||||
|
||||
type RequestUserLogin struct {
|
||||
Name string `form:"name"`
|
||||
Password string `form:"pwd"`
|
||||
@@ -57,3 +78,49 @@ type Auth struct {
|
||||
AccessSecret string `json:"AccessSecret"`
|
||||
AccessExpire int `json:"AccessExpire"`
|
||||
}
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
func (resp *Response) Set(Code int, Message string) {
|
||||
resp.Code = Code
|
||||
resp.Message = Message
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) {
|
||||
resp.Code = Code
|
||||
resp.Message = Message
|
||||
resp.Data = Data
|
||||
}
|
||||
|
||||
// SetMessage 设置Response的Message
|
||||
func (resp *Response) SetMessage(msg string) {
|
||||
resp.Message = msg
|
||||
}
|
||||
|
||||
// SetWithData 设置Data
|
||||
func (resp *Response) SetData(Data interface{}) {
|
||||
resp.Data = Data
|
||||
}
|
||||
|
||||
// SetWithData 设置Response的Code和Message值 带Data入参数
|
||||
func (resp *Response) SetCode(Code int) {
|
||||
resp.Code = Code
|
||||
}
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) {
|
||||
resp.Code = sr.Code
|
||||
resp.Message = sr.Message
|
||||
if len(data) == 1 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) {
|
||||
resp.Code = sr.Code
|
||||
resp.Message = msg
|
||||
if len(data) == 1 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user