diff --git a/net/ghttp/ghttp_request.go b/net/ghttp/ghttp_request.go index 2d3e4160c..7662af053 100644 --- a/net/ghttp/ghttp_request.go +++ b/net/ghttp/ghttp_request.go @@ -7,8 +7,8 @@ package ghttp import ( + "context" "fmt" - "github.com/gogf/gf/container/gmap" "github.com/gogf/gf/os/gres" "github.com/gogf/gf/os/gview" "net/http" @@ -32,7 +32,7 @@ type Request struct { LeaveTime int64 // Request ending time in microseconds. Middleware *Middleware // The middleware manager. StaticFile *StaticFile // Static file object when static file serving. - Context *gmap.StrAnyMap // Custom context map for internal usage purpose. + Context context.Context // Custom context map for internal usage purpose. handlers []*handlerParsedItem // All matched handlers containing handler, hook and middleware for this request . hasHookHandler bool // A bool marking whether there's hook handler in the handlers for performance purpose. hasServeHandler bool // A bool marking whether there's serving handler in the handlers for performance purpose. @@ -68,7 +68,7 @@ func newRequest(s *Server, r *http.Request, w http.ResponseWriter) *Request { Request: r, Response: newResponse(s, w), EnterTime: gtime.TimestampMilli(), - Context: gmap.NewStrAnyMap(), + Context: r.Context(), } request.Cookie = GetCookie(request) request.Session = s.sessionManager.New(request.GetSessionId()) diff --git a/net/ghttp/ghttp_unit_context_test.go b/net/ghttp/ghttp_unit_context_test.go index 4819adc73..d9f0636af 100644 --- a/net/ghttp/ghttp_unit_context_test.go +++ b/net/ghttp/ghttp_unit_context_test.go @@ -7,6 +7,7 @@ package ghttp_test import ( + "context" "fmt" "testing" "time" @@ -21,15 +22,15 @@ func Test_Context(t *testing.T) { s := g.Server(p) s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(func(r *ghttp.Request) { - r.Context.Set("traceid", 123) + r.Context = context.WithValue(r.Context, "traceid", 123) r.Middleware.Next() }) group.GET("/", func(r *ghttp.Request) { - r.Response.Write(r.Context.Get("traceid")) + r.Response.Write(r.Context.Value("traceid")) }) }) s.SetPort(p) - //s.SetDumpRouterMap(false) + s.SetDumpRouterMap(false) s.Start() defer s.Shutdown()