middleware

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	C_CTX_KEY_BEHAVIOR   = "behavior"
	C_BEHAVIOR_COST_WARN = 500 * time.Millisecond // api耗时超过阀值则log等级提升为warn
)

管理behavior的context中的key

Variables

View Source
var (
	TokenExpired     error = errors.New("Token is expired")
	TokenNotValidYet error = errors.New("Token not active yet")
	TokenMalformed   error = errors.New("That's not even a token")
	TokenInvalid     error = errors.New("Token is invalid")
)

一些常量

Functions

func Behavior

func Behavior(debugModel bool) gin.HandlerFunc

> 中间件[Behavior]

func BehaviorGet

func BehaviorGet(c *gin.Context, field TBehaviorField) interface{}

behavior get field's value

func BehaviorIgnore

func BehaviorIgnore(c *gin.Context)

behavior will be ignore

func BehaviorSet

func BehaviorSet(c *gin.Context, field TBehaviorField, val interface{})

behavior set field's value

func Corss

func Corss() gin.HandlerFunc

Cors 跨域配置 by gin-contrib.cors

func HeavierCostTrace

func HeavierCostTrace(c *gin.Context, traceModule string, d time.Duration)

behavior set cost_trace to add trace sub module of cost duration

func JWT

func JWT(cust IMetaClaimer, key []byte) *_jwt

==================== JWT签名工具结构

func StandardClaims

func StandardClaims(ttl time.Duration) jwt.StandardClaims

Create StandardClaims

Types

type IMetaClaimer

type IMetaClaimer interface {
	jwt.Claims
	TheUID() string
	TheUName() string
	TheStandardClaims() *jwt.StandardClaims
}

自定义荷载接口

type TBehaviorField

type TBehaviorField = string // 包里内置的几个字段(业务层可扩展)

管理behavior的字段数据类型

const (
	C_BEHAVIOR_CLIENT_IP  TBehaviorField = "client_ip"  // client ip
	C_BEHAVIOR_USER_ID    TBehaviorField = "uid"        // user id (string)(业务层)
	C_BEHAVIOR_REQUEST_ID TBehaviorField = "request_id" // request id (需请求头中含有C_REQ_HEAD_REQUEST_ID)
	C_BEHAVIOR_API        TBehaviorField = "api"        // api
	C_BEHAVIOR_METHOD     TBehaviorField = "method"     // Http Method
	C_BEHAVIOR_COST       TBehaviorField = "cost"       // 耗时(ms)
	C_BEHAVIOR_COST_TRACE TBehaviorField = "cost_trace" // 耗时追踪(ms)(业务层)
	C_BEHAVIOR_RETRY_AT   TBehaviorField = "retry_at"   // 重试时间((需请求头中含有C_REQ_HEAD_RETRY_AT))
	C_BEHAVIOR_REQ_HEAD   TBehaviorField = "head"       // 请求头
	C_BEHAVIOR_REQUEST    TBehaviorField = "request"    // 请求数据
	C_BEHAVIOR_STATUS     TBehaviorField = "status"     // 回应http状态码(int)
	C_BEHAVIOR_CODE       TBehaviorField = "code"       // 回应业务码(int)
	C_BEHAVIOR_RSPSIZE    TBehaviorField = "resp_size"  // 回应字节大小(KB)

	C_BEHAVIOR_RESPONSE  TBehaviorField = "response"      // 回应数据(不单独占用logger.field,使用message作为输出)
	C_BEHAVIOR_RESP_DATA TBehaviorField = "response_data" // 回应数据中的Data字段(不单独占用logger.field,仅逻辑用途)
)

Jump to

Keyboard shortcuts

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