refactor: gin or gweb
This commit is contained in:
parent
f5956750db
commit
66f7c93416
@ -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
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ package gweb
|
|||||||
|
|
||||||
import "github.com/gin-gonic/gin"
|
import "github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
type GinContext = gin.Context
|
||||||
type H = gin.H
|
type H = gin.H
|
||||||
type HandlersChain = gin.HandlersChain
|
type HandlersChain = gin.HandlersChain
|
||||||
type RouteInfo = gin.RouteInfo
|
type RouteInfo = gin.RouteInfo
|
||||||
|
Loading…
Reference in New Issue
Block a user