com

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ERROR_COMMON = 1000
	ERROR_PNR    = 2000
)
View Source
const (
	SUCCESS         = 0
	SUCCESS_MESSAGE = "success"

	ERROR_COMMON_OFFSET         = ERROR_COMMON + 1
	ERROR_COMMON_OFFSET_MESSAGE = "offset偏移量错误"

	ERROR_COMMON_LIMIT         = ERROR_COMMON + 2
	ERROR_COMMON_LIMIT_MESSAGE = "limit限制错误"

	ERROR_COMMON_IOUTIL_READALL         = ERROR_COMMON + 3
	ERROR_COMMON_IOUTIL_READALL_MESSAGE = "读取文件错误"

	ERROR_COMMON_UNMARSHAL         = ERROR_COMMON + 4
	ERROR_COMMON_UNMARSHAL_MESSAGE = "反序列化错误"

	ERROR_COMMON_GETLIST_COUNT         = ERROR_COMMON + 5
	ERROR_COMMON_GETLIST_COUNT_MESSAGE = "获取列表总数错误"

	ERROR_COMMON_GETLIST         = ERROR_COMMON + 6
	ERROR_COMMON_GETLIST_MESSAGE = "获取列表错误"

	ERROR_COMMON_DATABASE_GET         = ERROR_COMMON + 7
	ERROR_COMMON_DATABASE_GET_MESSAGE = "数据库查询错误"

	ERROR_COMMON_DATABASE_INSERT         = ERROR_COMMON + 8
	ERROR_COMMON_DATABASE_INSERT_MESSAGE = "数据库插入错误"

	ERROR_COMMON_DATABASE_UPDATE         = ERROR_COMMON + 9
	ERROR_COMMON_DATABASE_UPDATE_MESSAGE = "数据库更新错误"

	ERROR_COMMON_DATABASE_DELETE         = ERROR_COMMON + 10
	ERROR_COMMON_DATABASE_DELETE_MESSAGE = "数据库删除错误"

	ERROR_COMMON_ID_GET         = ERROR_COMMON + 11
	ERROR_COMMON_ID_GET_MESSAGE = "获取ID错误"

	ERROR_COMMON_PARAM_ID         = ERROR_COMMON + 12
	ERROR_COMMON_PARAM_ID_MESSAGE = "ID参数错误"

	ERROR_COMMON_TIME_FORMAT         = ERROR_COMMON + 13
	ERROR_COMMON_TIME_FORMAT_MESSAGE = "时间格式错误"

	ERROR_COMMON_BINDED         = ERROR_COMMON + 14
	ERROR_COMMON_BINDED_MESSAGE = "已绑定"

	ERROR_COMMON_UNAUTHORIZED         = ERROR_COMMON + 15
	ERROR_COMMON_UNAUTHORIZED_MESSAGE = "未授权"

	ERROR_COMMON_ENCRYPT         = ERROR_COMMON + 16
	ERROR_COMMON_ENCRYPT_MESSAGE = "加密错误"

	ERROR_COMMON_LOGIN         = ERROR_COMMON + 17
	ERROR_COMMON_LOGIN_MESSAGE = "登录错误"

	ERROR_COMMON_DUPLICATE         = ERROR_COMMON + 18
	ERROR_COMMON_DUPLICATE_MESSAGE = "数据重复"

	ERROR_COMMON_BAD_REQUEST         = ERROR_COMMON + 19
	ERROR_COMMON_BAD_REQUEST_MESSAGE = "错误的请求消息"

	ERROR_COMMON_FILE_SIZE         = ERROR_COMMON + 20
	ERROR_COMMON_FILE_SIZE_MESSAGE = "文件大小错误"

	ERROR_COMMON_FILE_READ         = ERROR_COMMON + 21
	ERROR_COMMON_FILE_READ_MESSAGE = "文件读取错误"

	ERROR_COMMON_FILE_IMPORT         = ERROR_COMMON + 22
	ERROR_COMMON_FILE_IMPORT_MESSAGE = "文件导入错误"

	ERROR_COMMON_PHONE_FORMAT         = ERROR_COMMON + 23
	ERROR_COMMON_PHONE_FORMAT_MESSAGE = "手机号格式错误"

	ERROR_COMMON_EMAIL_FORMAT         = ERROR_COMMON + 24
	ERROR_COMMON_EMAIL_FORMAT_MESSAGE = "邮箱格式错误"

	ERROR_COMMON_REQUEST_VERIFICATION         = ERROR_COMMON + 25
	ERROR_COMMON_REQUEST_VERIFICATION_MESSAGE = "请求参数验证失败"

	ERROR_COMMON_STSTEM_INTERNAL_FAULT         = ERROR_COMMON + 26
	ERROR_COMMON_STSTEM_INTERNAL_FAULT_MESSAGE = "系统内部故障"
)
View Source
const (
	ERROR_PNR_ROUTE_CALL         = ERROR_PNR + 1
	ERROR_PNR_ROUTE_CALL_MESSAGE = "路由调用失败"

	ERROR_PNR_COMET_CALL         = ERROR_PNR + 2
	ERROR_PNR_COMET_CALL_MESSAGE = "长连接调用失败"
)

Variables

View Source
var (
	AuthFailedErr = &Err{ErrStr: "认证失败", ErrCode: ERROR_COMMON_UNAUTHORIZED}
)

Functions

func CheckPageSize

func CheckPageSize(Size int) int

CheckPageSize 校验分页参数

func DecryptWithRSA

func DecryptWithRSA(cipherText string, privateKeyPath string) (string, error)

DecryptWithRSA rsa解密

func ERR

func ERR(ctx *gin.Context, v interface{})

func EncryptWithRSA

func EncryptWithRSA(plainText string, publicKeyPath string) (string, error)

EncryptWithRSA rsa加密

func GetToken

func GetToken(ctx *gin.Context) jwt.CustomData

GetToken 获取Token

func MWAuthentication

func MWAuthentication() gin.HandlerFunc

func MWCORS

func MWCORS() gin.HandlerFunc

func MWError

func MWError() gin.HandlerFunc

MWError 错误处理中间件

func OK

func OK(ctx *gin.Context, v interface{})

func Paginate

func Paginate(Page int, Size int) func(db *gorm.DB) *gorm.DB

Paginate 分页器

func SystemERR

func SystemERR(ctx *gin.Context, v interface{})

func TenantIdSpace

func TenantIdSpace(ctx *gin.Context) func(db *gorm.DB) *gorm.DB

TenantIdSpace 租户id隔离数据

func UserIdSpace

func UserIdSpace(ctx *gin.Context) func(db *gorm.DB) *gorm.DB

UserIdSpace 用户id隔离数据

Types

type CornTask

type CornTask struct {
	Tasks map[string]*ImplTask
	// contains filtered or unexported fields
}
var (
	Task *CornTask
)

func (*CornTask) AddTask

func (this *CornTask) AddTask(name string, task *ImplTask)

type Err

type Err struct {
	ErrStr     string // Error消息
	ErrCode    int    // Error状态码
	ErrComment string // Error详细描述
}

Err 自定义Error

func NewErr

func NewErr(errStr string, errCode int, errComment ...string) *Err

func (*Err) Error

func (ce *Err) Error() string

Error 实现了原生的Error接口,可用于获取Error信息

func (*Err) GetCode

func (ce *Err) GetCode() int

GetCode 用于获取ErrorCode,与项目中定义的Code绑定

func (*Err) Process

func (ce *Err) Process()

Process 当Result捕获到Error时,可使用Result的Process方法来调用本方法,达到使用自定义处理Error的需求

type ErrorResult

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

ErrorResult Err消化器(不要在意名字)

func Result

func Result(vs ...interface{}) *ErrorResult

Result 所谓的构造函数

func (*ErrorResult) Process

func (er *ErrorResult) Process(ef ...func(err error, data ...interface{}))

Process 如果Result捕获到了Err,就是用自定义的Err来处理

func (*ErrorResult) Unwrap

func (er *ErrorResult) Unwrap() interface{}

Unwrap 自动处理Error, 比较暴躁, 直接panic, 让中间件去兜底

type ImplTask

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

func NewTask

func NewTask() *ImplTask

func (*ImplTask) Interval

func (this *ImplTask) Interval(interval time.Duration) *ImplTask

func (*ImplTask) TaskFunc

func (this *ImplTask) TaskFunc(taskFunc func()) *ImplTask

type JsonResult

type JsonResult struct {
	Code    int         `json:"code"`
	Data    interface{} `json:"data"`
	Message interface{} `json:"message"`
}

func NewJsonResult

func NewJsonResult(code int, message interface{}, data interface{}) *JsonResult

type Namespaces

type Namespaces func(ctx *gin.Context) func(db *gorm.DB) *gorm.DB

Namespaces 数据隔离函数原型

type PageResult

type PageResult struct {
	Code      int         `json:"code"`
	Data      interface{} `json:"data"`
	Total     int64       `json:"total"`
	Message   interface{} `json:"message"`
	TotalPage int         `json:"total_page"`
}

func NewPageResult

func NewPageResult(code int, total int64, totalPage int, data interface{}, messages ...string) *PageResult

type ResultFunc

type ResultFunc func(result interface{}) func(output output)

func Response

func Response(ctx *gin.Context) ResultFunc

Jump to

Keyboard shortcuts

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