ginplus

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2020 License: MIT Imports: 15 Imported by: 0

README

go-gin

Documentation

Index

Constants

View Source
const (

	// UserIDKey 存储上下文中的键(用户ID)
	UserIDKey = prefix + "/user_id"
	// TraceIDKey 存储上下文中的键(跟踪ID)
	TraceIDKey = prefix + "/trace_id"
	// ResBodyKey 存储上下文中的键(响应Body数据)
	ResBodyKey = prefix + "/res_body"
)

定义上下文中的键

View Source
const (
	MSG_OK       = 0  // 成功
	MSG_ERR      = -1 // 错误
	MSG_REDIRECT = -2 // 重定向
	MSG_AUTH     = -3 // 登录认证
)

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(skipper ...SkipperFunc) gin.HandlerFunc

AuthMiddleware 用户授权中间件

func CorsMiddleware

func CorsMiddleware() gin.HandlerFunc

func GetBasicToken

func GetBasicToken(c *gin.Context) (string, string, error)

GetBasicToken 获取basic认证信息

func GetPageIndex

func GetPageIndex(c *gin.Context) int

GetPageIndex 获取分页的页索引

func GetPageSize

func GetPageSize(c *gin.Context) int

GetPageSize 获取分页的页大小(最大50)

func GetToken

func GetToken(c *gin.Context) string

GetToken 获取用户令牌

func GetUserID

func GetUserID(c *gin.Context) string

GetUserID 获取用户ID

func JoinRouter

func JoinRouter(method, path string) string

JoinRouter 拼接路由

func LogMiddleware

func LogMiddleware() gin.HandlerFunc

func NoMethodHandler

func NoMethodHandler() gin.HandlerFunc

NoMethodHandler 未找到请求方法的处理函数

func NoRouteHandler

func NoRouteHandler() gin.HandlerFunc

NoRouteHandler 未找到请求路由的处理函数

func ParseJSON

func ParseJSON(c *gin.Context, obj interface{}) error

ParseJSON 解析请求JSON

func RecoveryMiddleware

func RecoveryMiddleware() gin.HandlerFunc

RecoveryMiddleware 崩溃恢复中间件

func ResError

func ResError(c *gin.Context, err error)

ResError 响应错误

func ResJSON

func ResJSON(c *gin.Context, v interface{})

ResJSON 响应JSON数据

func ResList

func ResList(c *gin.Context, v interface{}, total int)

ResList 响应列表数据

func ResOK

func ResOK(c *gin.Context, v interface{})

ResOK 响应OK

func ResSuccess

func ResSuccess(c *gin.Context, v interface{})

ResSuccess 响应成功

func SetUserID

func SetUserID(c *gin.Context, userID string)

SetUserID 设定用户ID

Types

type Config

type Config struct {
	Address                   string
	ReadTimeout, WriteTimeout int64
}

type HTTPError

type HTTPError struct {
	Code    int    `json:"code" swaggo:"true,错误码"`
	Message string `json:"message" swaggo:"true,错误信息"`
}

HTTPItem HTTP响应错误项

type HTTPItem

type HTTPItem struct {
	Code    int         `json:"code" swaggo:"true,状态码"`
	Message string      `json:"message" swaggo:"true,状态信息"`
	Data    interface{} `json:"data" swaggo:"true,状态数据"`
}

HTTPItem HTTP响应项

type HTTPList

type HTTPList struct {
	List       interface{}     `json:"list"`
	Pagination *HTTPPagination `json:"pagination,omitempty"`
}

HTTPList HTTP响应列表数据

type HTTPPagination

type HTTPPagination struct {
	Total     int `json:"total"`
	PageIndex int `json:"pageIndex"`
	PageSize  int `json:"pageSize"`
}

HTTPPagination HTTP分页数据

func GetPaginationParam

func GetPaginationParam(c *gin.Context) *HTTPPagination

GetPaginationParam 获取分页查询参数

type HTTPStatus

type HTTPStatus struct {
	Status string `json:"status" swaggo:"true,状态(OK)"`
}

HTTPStatus HTTP响应状态

type ServerHttp

type ServerHttp struct {
	Server *http.Server
	Router *gin.Engine
	// contains filtered or unexported fields
}

func NewServerHttp

func NewServerHttp(cfg Config) (s ServerHttp, err error)

func (*ServerHttp) Close

func (s *ServerHttp) Close()

func (*ServerHttp) Listen

func (s *ServerHttp) Listen() (err error)

type SkipperFunc

type SkipperFunc func(*gin.Context) bool

SkipperFunc 定义中间件跳过函数

func AllowMethodAndPathPrefixSkipper

func AllowMethodAndPathPrefixSkipper(prefixes ...string) SkipperFunc

AllowMethodAndPathPrefixSkipper 检查请求方法和路径是否包含指定的前缀,如果不包含则跳过

func AllowPathPrefixNoSkipper

func AllowPathPrefixNoSkipper(prefixes ...string) SkipperFunc

AllowPathPrefixNoSkipper 检查请求路径是否包含指定的前缀,如果包含则不跳过

func AllowPathPrefixSkipper

func AllowPathPrefixSkipper(prefixes ...string) SkipperFunc

AllowPathPrefixSkipper 检查请求路径是否包含指定的前缀,如果包含则跳过

Jump to

Keyboard shortcuts

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