response

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 24 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthHandler gin.HandlerFunc
View Source
var Controllers = make([]Controller, 0)

Controllers controllers

View Source
var Default = &response{}
View Source
var DefaultLanguage = "zh-CN"

Functions

func AppendController

func AppendController(c Controller)

AppendController add controllers to Controllers

func Error

func Error(c *gin.Context, code int, err error, msg ...string)

Error 失败数据处理

func GetRequestLogger

func GetRequestLogger(c *gin.Context) *logger.Helper

GetRequestLogger 获取上下文提供的日志

func OK

func OK(c *gin.Context, data interface{}, msg ...string)

OK 通常成功数据处理

func PageOK

func PageOK(c *gin.Context, result interface{}, count int64, pageIndex int64, pageSize int64, msg ...string)

PageOK 分页数据处理

Types

type Api

type Api struct {
	Context *gin.Context
	Log     *logger.Helper
	Error   error
	// contains filtered or unexported fields
}

func (*Api) AddError

func (e *Api) AddError(err error)

func (*Api) Bind

func (e *Api) Bind(d interface{}, bindings ...binding.Binding) *Api

Bind 参数校验

func (*Api) Create

func (*Api) Create(c *gin.Context)

func (*Api) Delete

func (*Api) Delete(c *gin.Context)

func (Api) Err

func (e Api) Err(code int, err error, msg ...string)

Err 通常错误数据处理

func (*Api) Get

func (*Api) Get(c *gin.Context)

func (*Api) Handlers

func (*Api) Handlers() []gin.HandlerFunc

func (*Api) List

func (*Api) List(c *gin.Context)

func (*Api) Make

func (e *Api) Make(c *gin.Context) *Api

Make 设置http上下文

func (Api) OK

func (e Api) OK(data interface{}, msg ...string)

OK 通常成功数据处理

func (*Api) Other

func (*Api) Other(_ *gin.RouterGroup)

func (Api) PageOK

func (e Api) PageOK(result interface{}, count int64, pageIndex int64, pageSize int64, msg ...string)

PageOK 分页数据处理

func (*Api) Path

func (*Api) Path() string

func (*Api) SetEngine

func (e *Api) SetEngine(engine *gin.RouterGroup)

func (*Api) Update

func (*Api) Update(c *gin.Context)

type Controller

type Controller interface {
	// Path http path
	Path() string
	// Handlers middlewares
	Handlers() []gin.HandlerFunc
	// Create create
	Create(*gin.Context)
	// Update update
	Update(*gin.Context)
	// Delete delete
	Delete(*gin.Context)
	// Get get
	Get(*gin.Context)
	// List list
	List(*gin.Context)
	// Other other
	Other(*gin.RouterGroup)
}

Controller controllers

type DefaultController

type DefaultController struct {
	Api
	TableName string
	Auth      bool
	CreateReq interface{}
	UpdateReq interface{}
	DeleteReq interface{}
	GetReq    interface{}
	GetResp   interface{}
	ListReq   interface{}
	ListResp  interface{}
}

func (DefaultController) Create

func (e DefaultController) Create(c *gin.Context)

func (DefaultController) Delete

func (e DefaultController) Delete(c *gin.Context)

func (DefaultController) Get

func (e DefaultController) Get(c *gin.Context)

func (*DefaultController) Handlers

func (e *DefaultController) Handlers() []gin.HandlerFunc

func (DefaultController) List

func (e DefaultController) List(c *gin.Context)

func (*DefaultController) Path

func (e *DefaultController) Path() string

func (DefaultController) Update

func (e DefaultController) Update(c *gin.Context)

type Page

type Page struct {
	Count    int64 `json:"total"`
	Current  int64 `json:"current"`
	PageSize int64 `json:"pageSize"`
}

type Response

type Response struct {
	Success      bool   `json:"success,omitempty"`
	ErrorCode    string `json:"errorCode,omitempty"`
	ErrorMessage string `json:"errorMessage,omitempty"`
	ShowType     uint8  `json:"showType,omitempty"`
	TraceId      string `json:"traceId,omitempty"`
	Host         string `json:"host,omitempty"`
}

type Responses

type Responses interface {
	SetCode(int32)
	SetTraceID(string)
	SetMsg(...string)
	SetData(interface{})
	SetSuccess(bool)
	Clone() Responses
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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