refactor: gin or gweb
This commit is contained in:
parent
f5956750db
commit
66f7c93416
@ -7,14 +7,14 @@
|
||||
|
||||
package requestid
|
||||
|
||||
import "git.hexq.cn/tiglog/golib/gweb"
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
// Option for queue system
|
||||
type Option func(*config)
|
||||
|
||||
type (
|
||||
Generator func() string
|
||||
Handler func(c *gweb.Context, requestID string)
|
||||
Handler func(c *gin.Context, requestID string)
|
||||
)
|
||||
|
||||
type HeaderStrKey string
|
||||
|
@ -8,7 +8,7 @@
|
||||
package requestid
|
||||
|
||||
import (
|
||||
"git.hexq.cn/tiglog/golib/gweb"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
@ -26,7 +26,7 @@ type config struct {
|
||||
}
|
||||
|
||||
// New initializes the RequestID middleware.
|
||||
func New(opts ...Option) gweb.HandlerFunc {
|
||||
func New(opts ...Option) gin.HandlerFunc {
|
||||
cfg := &config{
|
||||
generator: func() string {
|
||||
return xid.New().String()
|
||||
@ -40,7 +40,7 @@ func New(opts ...Option) gweb.HandlerFunc {
|
||||
|
||||
headerXRequestID = string(cfg.headerKey)
|
||||
|
||||
return func(c *gweb.Context) {
|
||||
return func(c *gin.Context) {
|
||||
// Get id from request
|
||||
rid := c.GetHeader(headerXRequestID)
|
||||
if rid == "" {
|
||||
@ -57,6 +57,6 @@ func New(opts ...Option) gweb.HandlerFunc {
|
||||
}
|
||||
|
||||
// Get returns the request identifier
|
||||
func Get(c *gweb.Context) string {
|
||||
func Get(c *gin.Context) string {
|
||||
return c.GetHeader(headerXRequestID)
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ package gweb
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type GinContext = gin.Context
|
||||
type H = gin.H
|
||||
type HandlersChain = gin.HandlersChain
|
||||
type RouteInfo = gin.RouteInfo
|
||||
|
Loading…
Reference in New Issue
Block a user