api

package
v2.1.41 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 21 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 Config added in v2.1.23

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

type Context

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

func NewContext

func NewContext(g *gin.Context) Context

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

func (*Context) BindJSONValidator added in v2.1.23

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

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

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码 Deprecated: call RetJSON.

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 返回正常数据 Deprecated: call RetJSON.

type GinEngine added in v2.1.23

type GinEngine struct {
	Gin *gin.Engine

	IgnoreReleaseLog bool
	// contains filtered or unexported fields
}

func NewGinServer added in v2.1.23

func NewGinServer(ops ...Option) *GinEngine

func (*GinEngine) AddExitHook added in v2.1.23

func (g *GinEngine) AddExitHook(hooks ...HookFunc) *GinEngine

AddExitHook Add a hook function when the GinServer process exits

func (*GinEngine) AddShutdownHook added in v2.1.23

func (g *GinEngine) AddShutdownHook(hooks ...HookFunc) *GinEngine

AddShutdownHook Add a hook function for when the GinServer service is shut down

func (*GinEngine) Close added in v2.1.23

func (g *GinEngine) Close()

func (*GinEngine) Start added in v2.1.23

func (g *GinEngine) Start()

type HookFunc added in v2.1.23

type HookFunc func(c context.Context)

type Option added in v2.1.23

type Option func(o *Config)

func WithOpenTrace added in v2.1.23

func WithOpenTrace(open bool) Option

WithOpenTrace 设置超时时间

func WithServerDebug added in v2.1.23

func WithServerDebug(debug bool) Option

WithServerDebug 设置超时时间

func WithServerHost added in v2.1.23

func WithServerHost(addr string) Option

WithServerHost 设置host

func WithServerPort added in v2.1.23

func WithServerPort(port int) Option

WithServerPort 设置端口

func WithServerTimeout added in v2.1.23

func WithServerTimeout(dur time.Duration) Option

WithServerTimeout 设置超时时间

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