Skip to content

Commit 38a6fc5

Browse files
rafaeljustoaldas
authored andcommitted
Fix: Clarify limitations of custom context
The router expects the Echo Context to be the internal type `*context` ([reference](https://github.com/labstack/echo/blob/v4.2.2/router.go#L341)), so it cannot be replaced by a custom context before that. Currently, if you try to define the custom middleware before the router (via `Pre` method) the following panic will be raised: ``` echo: http: panic serving 172.23.0.1:49366: interface conversion: echo.Context is context.Context, not *echo.context goroutine 8 [running]: net/http.(*conn).serve.func1(0xc0001260a0) /usr/local/go/src/net/http/server.go:1824 +0x153 panic(0x803bc0, 0xc000114f90) /usr/local/go/src/runtime/panic.go:971 +0x499 github.com/labstack/echo/v4.(*Router).Find(0xc00000ea68, 0xc00002a260, 0x4, 0xc00002a265, 0xc, 0x8fc228, 0xc0000613e0) /go/pkg/mod/github.com/labstack/echo/[email protected]/router.go:341 +0x77e ```
1 parent 3841945 commit 38a6fc5

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

website/content/guide/context.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
4242

4343
> This middleware should be registered before any other middleware.
4444
45+
> The custom context cannot be defined in a middleware before the router ran (Pre)
46+
4547
**Use in handler**
4648

4749
```go

0 commit comments

Comments
 (0)