service

package
v1.1.5 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorBind = errors.New("missing required parameters")
)

Functions

func SetDefaultCode

func SetDefaultCode(code int64)

SetDefaultCode 设置默认返回code码

func SetDefaultData

func SetDefaultData(data interface{})

SetDefaultData 设置默认返回data内容

func SetDefaultMsg

func SetDefaultMsg(msg string)

SetDefaultMsg 设置默认返回msg内容

Types

type Response

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

func NewResponse

func NewResponse() Response

NewResponse 获取默认返回内容

type ServiceContext

type ServiceContext struct {
	*gin.Context
	*code_err.SvcContext
	R Response
}

func NewServiceContext

func NewServiceContext(g *gin.Context) *ServiceContext

NewContext 初始化上下文包含context.Context

func (*ServiceContext) BindValidator

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

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

func (*ServiceContext) Error

func (c *ServiceContext) Error(err error)

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

func (*ServiceContext) ErrorCodeMsg

func (c *ServiceContext) ErrorCodeMsg(code int64, msg string)

ErrorCodeMsg 直接指定code和msg

func (*ServiceContext) Response

func (c *ServiceContext) Response(code int64, msg string, data interface{})

Response 直接指定code和msg和data

func (*ServiceContext) Return

func (c *ServiceContext) Return(err *code_err.CodeErr)

func (*ServiceContext) SetData

func (c *ServiceContext) SetData(data interface{}) *code_err.CodeErr

Success 返回正常数据

func (*ServiceContext) Success

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

Success 返回正常数据

Jump to

Keyboard shortcuts

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