56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package controllers
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
type APIResponse struct {
|
|
Data interface{} `json:"data"`
|
|
Msg string `json:"msg"`
|
|
Code int `json:"code"`
|
|
}
|
|
|
|
func writeSuccess(c *gin.Context, httpStatus int, msg string, data interface{}) {
|
|
c.JSON(httpStatus, APIResponse{Data: data, Msg: msg, Code: httpStatus})
|
|
}
|
|
|
|
func writeError(c *gin.Context, httpStatus int, msg string) {
|
|
c.JSON(httpStatus, APIResponse{Data: nil, Msg: msg, Code: httpStatus})
|
|
}
|
|
|
|
// Swagger response model types
|
|
|
|
// SwagAPIResponse 通用API响应
|
|
type SwagAPIResponse struct {
|
|
Data interface{} `json:"data"` // 响应数据
|
|
Msg string `json:"msg"` // 响应消息
|
|
Code int `json:"code"` // HTTP状态码
|
|
}
|
|
|
|
// SwagPagination 分页信息
|
|
type SwagPagination struct {
|
|
CurrentPage int `json:"currentPage"` // 当前页码
|
|
PageSize int `json:"pageSize"` // 每页数量
|
|
TotalList int64 `json:"totalList"` // 总记录数
|
|
TotalPage int `json:"totalPage"` // 总页数
|
|
}
|
|
|
|
// SwagPaginationData 分页响应数据
|
|
type SwagPaginationData struct {
|
|
List interface{} `json:"list"`
|
|
Pagination SwagPagination `json:"pagination"`
|
|
}
|
|
|
|
// SwagLoginRequest 登录请求
|
|
type SwagLoginRequest struct {
|
|
Username string `json:"username"` // 用户名
|
|
Password string `json:"password"` // 密码
|
|
}
|
|
|
|
// SwagRegisterRequest 注册请求
|
|
type SwagRegisterRequest struct {
|
|
Username string `json:"username"` // 用户名
|
|
Password string `json:"password"` // 密码
|
|
Role string `json:"role"` // 角色
|
|
FlavorType string `json:"flavorType"` // 类型
|
|
RegionIDs []uint32 `json:"regionIds"` // 区域ID列表
|
|
}
|