Documentation
¶
Index ¶
- Constants
- Variables
- func Behavior(debugModel bool) gin.HandlerFunc
- func BehaviorGet(c *gin.Context, field TBehaviorField) interface{}
- func BehaviorIgnore(c *gin.Context)
- func BehaviorSet(c *gin.Context, field TBehaviorField, val interface{})
- func Corss() gin.HandlerFunc
- func HeavierCostTrace(c *gin.Context, traceModule string, d time.Duration)
- func JWT(cust IMetaClaimer, key []byte) *_jwt
- func StandardClaims(ttl time.Duration) jwt.StandardClaims
- type IMetaClaimer
- type TBehaviorField
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 BehaviorGet ¶
func BehaviorGet(c *gin.Context, field TBehaviorField) interface{}
behavior get field's value
func BehaviorSet ¶
func BehaviorSet(c *gin.Context, field TBehaviorField, val interface{})
behavior set field's value
func HeavierCostTrace ¶
behavior set cost_trace to add trace sub module of cost duration
func 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,仅逻辑用途) )
Click to show internal directories.
Click to hide internal directories.