response

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: MIT Imports: 18 Imported by: 12

Documentation

Index

Constants

View Source
const (
	Get     = "get"
	Base    = "base"
	Delete  = "delete"
	Search  = "search"
	Control = "control"
)

Variables

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

Controllers controllers

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 Action added in v0.0.9

type Action interface {
	fmt.Stringer
	Handler() gin.HandlerFunc
}

Action interface

type Api

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

func Make added in v0.0.9

func Make(c *gin.Context) *Api

Make 设置http上下文, 返回api

func (*Api) AddError

func (e *Api) AddError(err error) *Api

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, 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.HandlersChain
	// GetAction get action
	GetAction(string) Action
	// Other handler
	Other(*gin.RouterGroup)
	// GetKey get key
	GetKey() string
}

Controller controllers

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
}
var Default Responses = &response{}

type Searcher added in v0.0.9

type Searcher interface {
	GetPage() int64
	GetPageSize() int64
}

Searcher search interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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