Skip to content

Commit a91c40d

Browse files
committed
fiber.Context implements context.Context
1 parent 16fb08f commit a91c40d

File tree

3 files changed

+5
-60
lines changed

3 files changed

+5
-60
lines changed

ctx.go

+2-27
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package fiber
77
import (
88
"bufio"
99
"bytes"
10-
"context"
1110
"crypto/tls"
1211
"errors"
1312
"fmt"
@@ -41,10 +40,7 @@ const (
4140

4241
// The contextKey type is unexported to prevent collisions with context keys defined in
4342
// other packages.
44-
type contextKey int
45-
46-
// userContextKey define the key name for storing context.Context in *fasthttp.RequestCtx
47-
const userContextKey contextKey = 0 // __local_user_context__
43+
type contextKey int //nolint:unused // need for future (nolintlint)
4844

4945
// DefaultCtx is the default implementation of the Ctx interface
5046
// generation tool `go install github.com/vburenin/ifacemaker@975a95966976eeb2d4365a7fb236e274c54da64c`
@@ -391,23 +387,6 @@ func (c *DefaultCtx) RequestCtx() *fasthttp.RequestCtx {
391387
return c.fasthttp
392388
}
393389

394-
// Context returns a context implementation that was set by
395-
// user earlier or returns a non-nil, empty context,if it was not set earlier.
396-
func (c *DefaultCtx) Context() context.Context {
397-
ctx, ok := c.fasthttp.UserValue(userContextKey).(context.Context)
398-
if !ok {
399-
ctx = context.Background()
400-
c.SetContext(ctx)
401-
}
402-
403-
return ctx
404-
}
405-
406-
// SetContext sets a context implementation by user.
407-
func (c *DefaultCtx) SetContext(ctx context.Context) {
408-
c.fasthttp.SetUserValue(userContextKey, ctx)
409-
}
410-
411390
// Cookie sets a cookie by passing a cookie struct.
412391
func (c *DefaultCtx) Cookie(cookie *Cookie) {
413392
fcookie := fasthttp.AcquireCookie()
@@ -1838,12 +1817,8 @@ func (c *DefaultCtx) Vary(fields ...string) {
18381817
c.Append(HeaderVary, fields...)
18391818
}
18401819

1841-
// Value makes it possible to pass any values under keys scoped to the request
1820+
// Value makes it possible to retrieve values (Locals) under keys scoped to the request
18421821
// and therefore available to all following routes that match the request.
1843-
//
1844-
// All the values are removed from ctx after returning from the top
1845-
// RequestHandler. Additionally, Close method is called on each value
1846-
// implementing io.Closer before removing the value from ctx.
18471822
func (c *DefaultCtx) Value(key any) any {
18481823
return c.fasthttp.UserValue(key)
18491824
}

ctx_interface_gen.go

+1-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ctx_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,7 @@ func Test_Ctx_Deadline(t *testing.T) {
21972197
app.Get("/test", func(c Ctx) error {
21982198
deadline, ok := c.Deadline()
21992199
require.Equal(t, time.Time{}, deadline)
2200-
require.Equal(t, require.False, ok)
2200+
require.False(t, ok)
22012201
return nil
22022202
})
22032203
resp, err := app.Test(httptest.NewRequest(MethodGet, "/test", nil))
@@ -2229,7 +2229,7 @@ func Test_Ctx_Err(t *testing.T) {
22292229
return c.Next()
22302230
})
22312231
app.Get("/test", func(c Ctx) error {
2232-
require.Equal(t, require.NoError, c.Err())
2232+
require.NoError(t, c.Err())
22332233
return nil
22342234
})
22352235
resp, err := app.Test(httptest.NewRequest(MethodGet, "/test", nil))

0 commit comments

Comments
 (0)