bzgin

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLogHandler

func AccessLogHandler(f func(log *ResponseLog)) gin.HandlerFunc

AccessLogHandler 获取请求数据log

func Authorization

func Authorization(ctx *gin.Context) string

func BadRequestResponse

func BadRequestResponse(c *gin.Context, message string, reason ...string)

func Cors

func Cors(urls ...string) gin.HandlerFunc

Cors 跨域

func CtxGet

func CtxGet[T any](ctx *gin.Context, key string) (T, bool)

func CtxQuery

func CtxQuery[T any](ctx *gin.Context, key string) (T, bool)

func CtxQueryInt

func CtxQueryInt(ctx *gin.Context, key string, def ...int) int

func DefaultLog

func DefaultLog(file string) error

func ErrorResponse

func ErrorResponse(c *gin.Context, message string, reason ...string)

func FileDataStream

func FileDataStream(ctx *gin.Context, file string) error

FileDataStream 封装返回文件流

func FileStream

func FileStream(ctx *gin.Context, file string)

FileStream 封装返回文件流

func FilterBindErr

func FilterBindErr[T any](err error) error

FilterBindErr 自定义错误消息

func HttpHost

func HttpHost(ctx *gin.Context) string

func HttpLogger added in v0.0.5

func HttpLogger(config *lumberjack.Logger) gin.HandlerFunc

func IsHttps

func IsHttps(ctx *gin.Context) bool

func NoCache added in v0.0.5

func NoCache() gin.HandlerFunc

NoCache is a middleware function that appends headers to prevent the client from caching the HTTP response. 强制浏览器不使⽤缓存

func Recover

func Recover(isPrintStack, isOutStackErr bool, f func(c *gin.Context, err error)) gin.HandlerFunc

func Secure added in v0.0.5

func Secure() gin.HandlerFunc

Secure is a middleware function that appends security and resource access headers. ⼀些安全设置

func SuccessResponse

func SuccessResponse(c *gin.Context, data any, message ...string)

func ValidateHeader

func ValidateHeader[T any](f func(ctx *gin.Context, param *T), errFunc ...ValidateErrFunc) func(ctx *gin.Context)

func ValidateHeaderWithFilter

func ValidateHeaderWithFilter[T any](f func(ctx *gin.Context, param *T), errFunc ...ValidateErrFunc) func(ctx *gin.Context)

func ValidateJson

func ValidateJson[T any](f func(ctx *gin.Context, param *T), errFunc ...ValidateErrFunc) func(ctx *gin.Context)

func ValidateJsonWithFilter

func ValidateJsonWithFilter[T any](f func(ctx *gin.Context, param *T), errFunc ...ValidateErrFunc) func(ctx *gin.Context)

func ValidateQuery

func ValidateQuery[T any](f func(ctx *gin.Context, param *T), errFunc ...ValidateErrFunc) func(ctx *gin.Context)

func ValidateQueryWithFilter

func ValidateQueryWithFilter[T any](f func(ctx *gin.Context, param *T), errFunc ...ValidateErrFunc) func(ctx *gin.Context)

func ValidateUri

func ValidateUri[T any](f func(ctx *gin.Context, param *T), errFunc ...ValidateErrFunc) func(ctx *gin.Context)

func ValidateUriWithFilter

func ValidateUriWithFilter[T any](f func(ctx *gin.Context, param *T), errFunc ...ValidateErrFunc) func(ctx *gin.Context)

Types

type Claims

type Claims[C any] struct {
	Data C
	jwt.StandardClaims
}

type GinServer

type GinServer struct {
	*gin.Engine
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ip string, port int, fs ...func(r *gin.Engine)) *GinServer

func (*GinServer) Start

func (s *GinServer) Start() error

type Jwt

type Jwt[C any, I any] struct {
	// contains filtered or unexported fields
}

func NewJwt

func NewJwt[C any, T any](signingKey string) *Jwt[C, T]

func (*Jwt[C, T]) CheckJwtToken

func (j *Jwt[C, T]) CheckJwtToken(tokenString string) (string, error)

CheckJwtToken 简单校验和过滤token

func (*Jwt[C, T]) GenToken

func (j *Jwt[C, T]) GenToken(f func(claims *Claims[C]) *Claims[C], expireTime time.Duration) (string, error)

func (*Jwt[C, T]) GetJwtData

func (j *Jwt[C, T]) GetJwtData(c *gin.Context) (T, bool)

func (*Jwt[C, T]) Handler

func (j *Jwt[C, T]) Handler(
	dataFunc func(claims C, token string) (data T, msg string, err error),
	badResponseFuncs ...func(c *gin.Context, msg string, err error),
) gin.HandlerFunc

func (*Jwt[C, T]) ParseJwtInfo

func (j *Jwt[C, T]) ParseJwtInfo(token string) (C, bool, error)

ParseJwtInfo 解析token

type Response

type Response struct {
	Code       int    `json:"code"`
	Message    string `json:"message"`
	ReasonCode string `json:"reasonCode"`
	Reason     string `json:"reason"`
	Data       any    `json:"data"`
}

type ResponseLog

type ResponseLog struct {
	Url         string
	Method      string
	Status      int
	ContentType string
	Param       string
	Content     string
	Header      map[string][]string
	SpendTime   string
	IP          string
	UserAgent   string
}

type ValidateErrFunc

type ValidateErrFunc func(ctx *gin.Context, err error)

Jump to

Keyboard shortcuts

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