mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
change attribute Context to context.Context for ghttp.Request
This commit is contained in:
@ -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())
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user