ginutil

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MRelease = 1 << iota // Gin release 模式
	MSwagger             // 开启Swagger

	// 中间件启用
	MTraceId       // 请求context 加入TraceId
	MReqLogger     //请求日志
	MDumpBody      // Dump 请求参数&返回参数
	MRecoverLogger // Recover 日志写入到日志中心

	MStd = MSwagger | MTraceId | MReqLogger | MDumpBody // 默认
)

Variables

View Source
var AuthorizationHeader = "X-Authorization"
View Source
var JWTDataKey = "jwt_claims_data"
View Source
var SignValidDuration = 5 * time.Second
View Source
var SignatureHeader = "X-Signature"

Functions

func AddSkipPaths

func AddSkipPaths(paths ...string)

AddSkipPaths 添加的Path不会被日志记录

func ApiSignVerify

func ApiSignVerify(enable bool, method sign.Method, supportMethods []string, getSecretKey func(accessKey string) (string, error)) gin.HandlerFunc

ApiSignVerify API hmacSha1 接口签名 必需设置获取密钥的方法

func ClientIP

func ClientIP(c *gin.Context) string

优选获取 X-Forwarded-For, X-Real-Ip

func ContextWithTraceId

func ContextWithTraceId() gin.HandlerFunc

func DefaultEngine

func DefaultEngine(flags int) *gin.Engine

func DumpBodyLogger

func DumpBodyLogger(skipPaths ...string) gin.HandlerFunc

DumpBodyLogger Dump 请求和返回Body便于排查问题

func GenJWTToken

func GenJWTToken(data string, ttl time.Duration, signingKey ...string) (token string, err error)

func GetJWTDataFromContext

func GetJWTDataFromContext(c *gin.Context) (string, bool)

func JWTAuthVerify

func JWTAuthVerify(enable bool, signingKey ...string) gin.HandlerFunc

JWTAuthVerify JWT权限验证 signingKey 自定义的 加密Key, 如果没有就使用全局默认的

func RecoveryLogger

func RecoveryLogger() gin.HandlerFunc

RecoveryLogger GIN Recovery错误日志

func ReqLogger

func ReqLogger(skipPaths ...string) gin.HandlerFunc

ReqLogger GIN 请求日志拦截到日志系统中

func Resp

func Resp(c *gin.Context, httpCode int, data interface{}, err error)

func RespData

func RespData(c *gin.Context, data interface{}, status ...int)

RespData

func RespErr

func RespErr(c *gin.Context, err error, status ...int)

func RespSuccess

func RespSuccess(c *gin.Context, status ...int)

RespSuccess

func SetJWTDataToContext

func SetJWTDataToContext(c *gin.Context, token string, signingKey ...string) error

func ShouldBind

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

func ValidateStruct

func ValidateStruct(obj interface{}) error

Types

type BaseResp

type BaseResp struct {
	errc.Error
	TraceID string `json:"traceId"`
}

func NewBaseResp

func NewBaseResp(code int, msg string) *BaseResp

func (*BaseResp) WriteTraceID

func (b *BaseResp) WriteTraceID(c *gin.Context) *BaseResp

type DataResp

type DataResp struct {
	*BaseResp
	Data interface{} `json:"data"`
}

func NewDataResp

func NewDataResp(baseResp *BaseResp, data interface{}) *DataResp

type ResponseErr

type ResponseErr struct {
	Method   string
	Path     string
	IP       string
	Form     url.Values
	PostForm url.Values
	Func     string
	Error    string
}

Jump to

Keyboard shortcuts

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