Documentation ¶
Index ¶
- Constants
- func AuthMiddleware(skipper ...SkipperFunc) gin.HandlerFunc
- func CorsMiddleware() gin.HandlerFunc
- func GetBasicToken(c *gin.Context) (string, string, error)
- func GetPageIndex(c *gin.Context) int
- func GetPageSize(c *gin.Context) int
- func GetToken(c *gin.Context) string
- func GetUserID(c *gin.Context) string
- func JoinRouter(method, path string) string
- func LogMiddleware() gin.HandlerFunc
- func NoMethodHandler() gin.HandlerFunc
- func NoRouteHandler() gin.HandlerFunc
- func ParseJSON(c *gin.Context, obj interface{}) error
- func RecoveryMiddleware() gin.HandlerFunc
- func ResError(c *gin.Context, err error)
- func ResJSON(c *gin.Context, v interface{})
- func ResList(c *gin.Context, v interface{}, total int)
- func ResOK(c *gin.Context, v interface{})
- func ResSuccess(c *gin.Context, v interface{})
- func SetUserID(c *gin.Context, userID string)
- type Config
- type HTTPError
- type HTTPItem
- type HTTPList
- type HTTPPagination
- type HTTPStatus
- type ServerHttp
- type SkipperFunc
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 ¶
GetBasicToken 获取basic认证信息
func LogMiddleware ¶
func LogMiddleware() gin.HandlerFunc
Types ¶
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 ¶
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 检查请求路径是否包含指定的前缀,如果包含则跳过
Click to show internal directories.
Click to hide internal directories.