web

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR   = -1
	SUCCESS = 0

	CreateSuccess = "创建成功"
	UpdateSuccess = "更新成功"
	DeleteSuccess = "删除成功"
	GetSuccess    = "获取成功"
	OkSuccess     = "操作成功"
	Succeed       = "成功"
)

Variables

View Source
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 GinException

func GinException() gin.HandlerFunc

GinException 异常处理中间件

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 BindOption func(obj any) error

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) GetData added in v0.0.5

func (r *DefaultResult) GetData() any

GetData 获取数据

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) CreateOK

func (g *GinActionImpl) CreateOK()

CreateOK 创建成功

func (*GinActionImpl) CreateOkWithMessage

func (g *GinActionImpl) CreateOkWithMessage(message string)

CreateOkWithMessage 创建成功并返回消息

func (*GinActionImpl) DeleteOK

func (g *GinActionImpl) DeleteOK()

DeleteOK 删除成功

func (*GinActionImpl) DeleteOkWithMessage

func (g *GinActionImpl) DeleteOkWithMessage(message string)

DeleteOkWithMessage 删除成功并返回消息

func (*GinActionImpl) Error

func (g *GinActionImpl) Error(err any)

Error 失败

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) Success

func (g *GinActionImpl) Success(data any)

Success 成功

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) UpdateOK

func (g *GinActionImpl) UpdateOK()

UpdateOK 更新成功

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 NewLogger

func NewLogger(args interface{}) *Logger

func (*Logger) AddErrorLog

func (l *Logger) AddErrorLog(fields map[string]interface{})

AddErrorLog 添加错误日志

func (*Logger) AddInfoLog

func (l *Logger) AddInfoLog(fields map[string]interface{})

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接口

func NewResponse

func NewResponse(code int, message string, result any) *Response

NewResponse 创建返回数据

type Validate

type Validate struct {
	// contains filtered or unexported fields
}

func NewValidate

func NewValidate() *Validate

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL