response

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 19 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// Get action
	Get = "get"
	// Base action
	Base = "base"
	// Delete action
	Delete = "delete"
	// Search action
	Search = "search"
	// Control action
	Control = "control"
	// Create action
	Create = "create"
	// Update action
	Update = "update"
)

Variables

View Source
var AuthHandler gin.HandlerFunc

AuthHandler 鉴权

View Source
var Controllers = make([]Controller, 0)

Controllers controllers

View Source
var DefaultLanguage = "zh-CN"

DefaultLanguage 默认语言

View Source
var VerifyHandler func(ctx *gin.Context) security.Verifier

Functions

func AppendController

func AppendController(c Controller)

AppendController add controllers to Controllers

func GetRequestLogger

func GetRequestLogger(c *gin.Context) *slog.Logger

GetRequestLogger 获取上下文提供的日志

Types

type API

type API struct {
	Context *gin.Context
	Log     *slog.Logger
	Error   error
	// contains filtered or unexported fields
}

API api接口

func Make

func Make(c *gin.Context) *API

Make 设置http上下文, 返回api

func (*API) AddError

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

AddError 添加错误

func (*API) Bind

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

Bind 参数校验

func (*API) Create

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

Create 创建

func (*API) Delete

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

Delete 删除

func (*API) Err

func (e *API) Err(code int, msg ...string)

Err 通常错误数据处理

func (*API) Get

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

Get 获取

func (*API) Handlers

func (*API) Handlers() gin.HandlersChain

Handlers 路由

func (*API) List

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

List 列表

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)

Other 其他方法

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

Path 路径

func (*API) SetEngine

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

SetEngine 设置路由组

func (*API) Update

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

Update 更新

type Action

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

Action interface

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"`
}

Page page

type Response

type Response struct {
	Success      bool   `json:"success,omitempty"`
	Status       string `json:"status,omitempty"`
	Code         int    `json:"code,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"`
}

Response response

type Responses

type Responses interface {
	SetCode(int)
	SetTraceID(string)
	SetMsg(...string)
	SetList(interface{})
	SetStatus(string)
	Clone() Responses
	Error(ctx *gin.Context, code int, err error, msg ...string)
	OK(ctx *gin.Context, data any)
	PageOK(ctx *gin.Context, result any, count, pageIndex, pageSize int64)
}

Responses responses

var Default Responses = &response{}

Default 默认返回

type Searcher

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

Searcher search interface

Directories

Path Synopsis
mgm

Jump to

Keyboard shortcuts

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