mgin

package
v0.7.9 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

go-tools

mgin

func Apply(c *gin.Context) {
	getGin := swmGin.GetGin(c)
	// 1.
	// getGin.Response400Str("错误")
	// 2. 
	// err := errors.New("错误")
	// getGin.Response400(err)
	// 3.
	getGin.ResponseSuc(nil)
}

Documentation

Index

Constants

View Source
const DefaultLimit = 20

修改全局 limit 大小

Variables

This section is empty.

Functions

func GetPage

func GetPage(c *gin.Context) int

GetPage 保证了各接口的page处理是一致的

func GetPageLimit

func GetPageLimit(c *gin.Context, limit int) int

GetPageLimit 自定义单个请求 limit 大小

func MarkError

func MarkError(v string)

MarkError 将错误 存入日志

Types

type Error

type Error interface {
	error
	Code() int
}

Error 带有错误码 与 错误信息的错误类

func ErrNew

func ErrNew(code int, text string) Error

ErrNew returns an error that formats as the given text.

type Gin

type Gin struct {
	C *gin.Context
}

Gin 实体

func GetGin

func GetGin(c *gin.Context) Gin

GetGin 获取Gin

func (*Gin) Response

func (g *Gin) Response(httpCode, errCode int, msg string, data interface{})

Response

func (*Gin) Response400

func (g *Gin) Response400(err error, msg string)

Response400 返回失败, err记录日志错误,msg提示用户

func (*Gin) Response400Str

func (g *Gin) Response400Str(msg string)

Response400Str msg提示用户

func (*Gin) Response500

func (g *Gin) Response500(err error)

Response500 返回失败

func (*Gin) ResponseCodeError

func (g *Gin) ResponseCodeError(error Error)

ResponseFailError 返回自定义的错误码

func (*Gin) ResponseFailValidParam

func (g *Gin) ResponseFailValidParam(err error)

ResponseFailValidParam 验证参数错误

func (*Gin) ResponseSuc

func (g *Gin) ResponseSuc(data interface{})

ResponseSuc 返回成功

func (*Gin) ResponseSucNoData

func (g *Gin) ResponseSucNoData()

ResponseSucNoData 返回成功

Jump to

Keyboard shortcuts

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