Compare commits
2 Commits
2757e4f3c3
...
f5956750db
Author | SHA1 | Date | |
---|---|---|---|
f5956750db | |||
64679cfdca |
@ -7,14 +7,14 @@
|
||||
|
||||
package requestid
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import "git.hexq.cn/tiglog/golib/gweb"
|
||||
|
||||
// Option for queue system
|
||||
type Option func(*config)
|
||||
|
||||
type (
|
||||
Generator func() string
|
||||
Handler func(c *gin.Context, requestID string)
|
||||
Handler func(c *gweb.Context, requestID string)
|
||||
)
|
||||
|
||||
type HeaderStrKey string
|
||||
|
@ -8,7 +8,7 @@
|
||||
package requestid
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"git.hexq.cn/tiglog/golib/gweb"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
@ -26,7 +26,7 @@ type config struct {
|
||||
}
|
||||
|
||||
// New initializes the RequestID middleware.
|
||||
func New(opts ...Option) gin.HandlerFunc {
|
||||
func New(opts ...Option) gweb.HandlerFunc {
|
||||
cfg := &config{
|
||||
generator: func() string {
|
||||
return xid.New().String()
|
||||
@ -40,7 +40,7 @@ func New(opts ...Option) gin.HandlerFunc {
|
||||
|
||||
headerXRequestID = string(cfg.headerKey)
|
||||
|
||||
return func(c *gin.Context) {
|
||||
return func(c *gweb.Context) {
|
||||
// Get id from request
|
||||
rid := c.GetHeader(headerXRequestID)
|
||||
if rid == "" {
|
||||
@ -57,6 +57,6 @@ func New(opts ...Option) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// Get returns the request identifier
|
||||
func Get(c *gin.Context) string {
|
||||
func Get(c *gweb.Context) string {
|
||||
return c.GetHeader(headerXRequestID)
|
||||
}
|
||||
|
@ -98,6 +98,9 @@ func SetLevel(level Level) { std.SetLevel(level) }
|
||||
func With(fields ...Field) {
|
||||
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 Info(msg string, fields ...Field) { std.Info(msg, fields...) }
|
||||
|
Loading…
Reference in New Issue
Block a user