Compare commits

..

No commits in common. "f5956750db0f0d46783e14aa553fe5ccddbfaaac" and "2757e4f3c30995aec20210fcfd27d545ef7f8cf9" have entirely different histories.

3 changed files with 6 additions and 9 deletions

View File

@ -7,14 +7,14 @@
package requestid package requestid
import "git.hexq.cn/tiglog/golib/gweb" import "github.com/gin-gonic/gin"
// Option for queue system // Option for queue system
type Option func(*config) type Option func(*config)
type ( type (
Generator func() string Generator func() string
Handler func(c *gweb.Context, requestID string) Handler func(c *gin.Context, requestID string)
) )
type HeaderStrKey string type HeaderStrKey string

View File

@ -8,7 +8,7 @@
package requestid package requestid
import ( import (
"git.hexq.cn/tiglog/golib/gweb" "github.com/gin-gonic/gin"
"github.com/rs/xid" "github.com/rs/xid"
) )
@ -26,7 +26,7 @@ type config struct {
} }
// New initializes the RequestID middleware. // New initializes the RequestID middleware.
func New(opts ...Option) gweb.HandlerFunc { func New(opts ...Option) gin.HandlerFunc {
cfg := &config{ cfg := &config{
generator: func() string { generator: func() string {
return xid.New().String() return xid.New().String()
@ -40,7 +40,7 @@ func New(opts ...Option) gweb.HandlerFunc {
headerXRequestID = string(cfg.headerKey) headerXRequestID = string(cfg.headerKey)
return func(c *gweb.Context) { return func(c *gin.Context) {
// Get id from request // Get id from request
rid := c.GetHeader(headerXRequestID) rid := c.GetHeader(headerXRequestID)
if rid == "" { if rid == "" {
@ -57,6 +57,6 @@ func New(opts ...Option) gweb.HandlerFunc {
} }
// Get returns the request identifier // Get returns the request identifier
func Get(c *gweb.Context) string { func Get(c *gin.Context) string {
return c.GetHeader(headerXRequestID) return c.GetHeader(headerXRequestID)
} }

View File

@ -98,9 +98,6 @@ func SetLevel(level Level) { std.SetLevel(level) }
func With(fields ...Field) { func With(fields ...Field) {
std.l.With(fields...) std.l.With(fields...)
} }
func WithRequestId(reqId string) {
std.l.With(String("reqId", reqId))
}
func Debug(msg string, fields ...Field) { std.Debug(msg, fields...) } func Debug(msg string, fields ...Field) { std.Debug(msg, fields...) }
func Info(msg string, fields ...Field) { std.Info(msg, fields...) } func Info(msg string, fields ...Field) { std.Info(msg, fields...) }