api

package
v2.1.14 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorBind      = errors.New("missing required parameters")
	TraceHeaderKey struct{}
)

Functions

func SetDefaultCode

func SetDefaultCode(code int)

SetDefaultCode 设置默认返回code码

func SetDefaultData

func SetDefaultData(data interface{})

SetDefaultData 设置默认返回data内容

func SetDefaultMsg

func SetDefaultMsg(msg string)

SetDefaultMsg 设置默认返回msg内容

Types

type Context

type Context struct {
	*gin.Context
	C context.Context
	R Response
	T *utils.TraceHeader
}

func NewContext

func NewContext(g *gin.Context) Context

NewContext 初始化上下文包含context.Context 对链路信息进行判断并且在Response时返回TraceId信息

func (*Context) BindValidator added in v2.0.3

func (c *Context) BindValidator(obj interface{}) error

BindValidator 参数绑定结构体,并且按照tag进行校验返回校验结果

func (*Context) Error

func (c *Context) Error(err error)

Error 返回异常信息,自动识别Code码

func (*Context) ErrorCodeMsg added in v2.0.5

func (c *Context) ErrorCodeMsg(code int, msg string)

ErrorCodeMsg 直接指定code和msg

func (*Context) Response added in v2.0.5

func (c *Context) Response(code int, msg string, data interface{})

Response 直接指定code和msg和data

func (*Context) RetJSON added in v2.1.7

func (c *Context) RetJSON(data interface{}, err error)

RetJSON 针对 ecode v2

func (*Context) Success

func (c *Context) Success(data interface{})

Success 返回正常数据

type Response

type Response struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

func NewResponse

func NewResponse() Response

NewResponse 获取默认返回内容

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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