Documentation ¶
Index ¶
- Constants
- Variables
- func GinException() gin.HandlerFunc
- func GinLoggerFormatter(param gin.LogFormatterParams) string
- func PrintStack()
- type Action
- type BindOption
- type DefaultResult
- type ErrorModel
- type GinActionImpl
- func (g *GinActionImpl) Bind(param any, opts ...BindOption) error
- func (g *GinActionImpl) BindParam(param interface{}) error
- func (g *GinActionImpl) BindUriParam(param interface{}) error
- func (g *GinActionImpl) CreateOK()
- func (g *GinActionImpl) CreateOkWithMessage(message string)
- func (g *GinActionImpl) DeleteOK()
- func (g *GinActionImpl) DeleteOkWithMessage(message string)
- func (g *GinActionImpl) Error(err any)
- func (g *GinActionImpl) ShouldBindBodyWith(param any, bb binding.BindingBody) error
- func (g *GinActionImpl) ShouldBindWith(param any, bb binding.Binding) error
- func (g *GinActionImpl) Success(data any)
- func (g *GinActionImpl) SuccessWithMessage(message string, data interface{})
- func (g *GinActionImpl) ThrowError(err *ErrorModel)
- func (g *GinActionImpl) ThrowValidateError(err error)
- func (g *GinActionImpl) UpdateOK()
- func (g *GinActionImpl) UpdateOkWithMessage(message string)
- type ListRequest
- type Logger
- type PageList
- type Request
- type Response
- type Validate
Constants ¶
const ( ERROR = -1 SUCCESS = 0 CreateSuccess = "创建成功" UpdateSuccess = "更新成功" DeleteSuccess = "删除成功" GetSuccess = "获取成功" OkSuccess = "操作成功" Succeed = "成功" )
Variables ¶
var ( ServerError = NewErrorModel(500, "服务器错误", nil, http.StatusInternalServerError) // UNAUTHORIZED 未登录 UNAUTHORIZED = NewErrorModel(10000, "未登录", nil, http.StatusUnauthorized) // InvalidToken 非法Token InvalidToken = NewErrorModel(10001, "非法Token", nil, http.StatusUnauthorized) // TokenExpired Token过期 TokenExpired = NewErrorModel(10002, "Token过期", nil, http.StatusUnauthorized) // UsernameOrPasswordError 用户名或密码错误 UsernameOrPasswordError = NewErrorModel(10003, "用户名或密码错误", nil, http.StatusUnauthorized) // PlatformNotExist 平台不存在 PlatformNotExist = NewErrorModel(10004, "平台不存在", nil, http.StatusPreconditionFailed) // PlatformIdCanNotEmpty 平台id不能为空 PlatformIdCanNotEmpty = NewErrorModel(10005, "平台id不能为空", nil, http.StatusPreconditionFailed) )
Functions ¶
func GinLoggerFormatter ¶
func GinLoggerFormatter(param gin.LogFormatterParams) string
func PrintStack ¶
func PrintStack()
Types ¶
type Action ¶
type Action interface { // Success 成功并返回数据 Success(data any) Error(err any) ThrowError(err *ErrorModel) ThrowValidateError(err error) Bind(param any, opts ...BindOption) error BindParam(param any) error BindUriParam(param any) error ShouldBindBodyWith(param any, bb binding.BindingBody) error ShouldBindWith(param any, bb binding.Binding) error CreateOK() UpdateOK() DeleteOK() SuccessWithMessage(message string, data any) CreateOkWithMessage(message string) UpdateOkWithMessage(message string) DeleteOkWithMessage(message string) }
type BindOption ¶ added in v0.0.4
type DefaultResult ¶ added in v0.0.5
type DefaultResult struct { Err *ErrorModel `json:"err"` Data any `json:"data"` }
DefaultResult 默认的返回数据结构,用于services处理完业务逻辑后返回给controller的数据结构
func NewDefaultResult ¶ added in v0.0.5
func NewDefaultResult() *DefaultResult
NewDefaultResult 创建默认的返回数据结构
func (*DefaultResult) GetError ¶ added in v0.0.5
func (r *DefaultResult) GetError() *ErrorModel
GetError 获取错误信息
func (*DefaultResult) IsError ¶ added in v0.0.5
func (r *DefaultResult) IsError() bool
IsError 判断时候有错误
func (*DefaultResult) SetData ¶ added in v0.0.5
func (r *DefaultResult) SetData(data any)
SetData 设置数据
func (*DefaultResult) SetError ¶ added in v0.0.5
func (r *DefaultResult) SetError(err error)
SetError 设置错误信息
func (*DefaultResult) SetResponse ¶ added in v0.0.5
func (r *DefaultResult) SetResponse(data any, err error)
SetResponse 设置返回数据
type ErrorModel ¶
type ErrorModel struct { Code int `json:"code" ` Message string `json:"message" ` Result interface{} `json:"result"` HttpStatus int `json:"httpStatus" swaggerignore:"true"` }
ErrorModel 错误模型
func NewErrorModel ¶
func NewErrorModel(code int, message string, result interface{}, httpStatus int) *ErrorModel
func (*ErrorModel) Error ¶
func (e *ErrorModel) Error() string
type GinActionImpl ¶
type GinActionImpl struct {
// contains filtered or unexported fields
}
func NewGinActionImpl ¶
func NewGinActionImpl(c *gin.Context) *GinActionImpl
func (*GinActionImpl) Bind ¶ added in v0.0.4
func (g *GinActionImpl) Bind(param any, opts ...BindOption) error
Bind 绑定参数 此方法需要传入多个gin的绑定方法 如果是绑定uri参数需要传入c.ShouldBindUri 需要将uri参数放在最后 否则会报错 结构体中的uri参数需要加上tag binding:"omitempty" 否则 c.ShouldBindUri 之前的绑定方法会报错
func (*GinActionImpl) BindParam ¶
func (g *GinActionImpl) BindParam(param interface{}) error
BindParam 绑定参数
func (*GinActionImpl) BindUriParam ¶ added in v0.0.4
func (g *GinActionImpl) BindUriParam(param interface{}) error
BindUriParam 绑定uri参数
func (*GinActionImpl) CreateOkWithMessage ¶
func (g *GinActionImpl) CreateOkWithMessage(message string)
CreateOkWithMessage 创建成功并返回消息
func (*GinActionImpl) DeleteOkWithMessage ¶
func (g *GinActionImpl) DeleteOkWithMessage(message string)
DeleteOkWithMessage 删除成功并返回消息
func (*GinActionImpl) ShouldBindBodyWith ¶ added in v0.0.4
func (g *GinActionImpl) ShouldBindBodyWith(param any, bb binding.BindingBody) error
ShouldBindBodyWith 绑定body参数
func (*GinActionImpl) ShouldBindWith ¶ added in v0.0.4
func (g *GinActionImpl) ShouldBindWith(param any, bb binding.Binding) error
ShouldBindWith 绑定参数
func (*GinActionImpl) SuccessWithMessage ¶
func (g *GinActionImpl) SuccessWithMessage(message string, data interface{})
SuccessWithMessage 成功并返回消息
func (*GinActionImpl) ThrowError ¶
func (g *GinActionImpl) ThrowError(err *ErrorModel)
ThrowError 抛出错误
func (*GinActionImpl) ThrowValidateError ¶
func (g *GinActionImpl) ThrowValidateError(err error)
ThrowValidateError 参数验证错误抛出异常
func (*GinActionImpl) UpdateOkWithMessage ¶
func (g *GinActionImpl) UpdateOkWithMessage(message string)
UpdateOkWithMessage 更新成功并返回消息
type ListRequest ¶
type ListRequest struct { Page int `form:"page" json:"page" query:"page" binding:"required"` PageSize int `form:"page_size" json:"page_size" query:"page_size" binding:"required"` Order string `form:"order" json:"order" query:"order" msg:"排序" ` Field string `form:"field" json:"field" query:"field" msg:"排序字段" ` }
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func (*Logger) AddErrorLog ¶
AddErrorLog 添加错误日志
func (*Logger) AddInfoLog ¶
AddInfoLog 添加信息日志
type PageList ¶
type PageList[T interface{}] struct { Total int64 `json:"total" ` Data []T `json:"data" ` Page int `json:"page" ` PageSize int `json:"page_size" ` }
PageList 分页数据
func NewPageList ¶
func NewPageList[T interface{}]() *PageList[T]
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func NewRequest ¶
func NewRequest() *Request
func (*Request) GetValidateErr ¶
func (r *Request) GetValidateErr(err error, obj interface{}) *ErrorModel
GetValidateErr 获取校验错误信息 传入错误对象和对象 对象tag为json form uri query header
type Response ¶
type Response struct { Code int `json:"code" ` Result any `json:"result"` Message string `json:"message" ` }
Response 返回数据用于api接口
type Validate ¶
type Validate struct {
// contains filtered or unexported fields
}
func NewValidate ¶
func NewValidate() *Validate