mirror of
https://github.com/labstack/echo.git
synced 2025-01-26 03:20:08 +02:00
Changed standard#WrapMiddleware
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
f730def2c6
commit
fbf37ec2f4
@ -8,12 +8,14 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
// Engine defines an interface for HTTP server.
|
||||
Engine interface {
|
||||
SetHandler(Handler)
|
||||
SetLogger(*log.Logger)
|
||||
Start()
|
||||
}
|
||||
|
||||
// Request defines an interface for HTTP request.
|
||||
Request interface {
|
||||
TLS() bool
|
||||
Scheme() string
|
||||
@ -31,6 +33,7 @@ type (
|
||||
Object() interface{}
|
||||
}
|
||||
|
||||
// Response defines an interface for HTTP response.
|
||||
Response interface {
|
||||
Header() Header
|
||||
WriteHeader(int)
|
||||
@ -43,6 +46,7 @@ type (
|
||||
Object() interface{}
|
||||
}
|
||||
|
||||
// Header defines an interface for HTTP header.
|
||||
Header interface {
|
||||
Add(string, string)
|
||||
Del(string)
|
||||
@ -51,6 +55,7 @@ type (
|
||||
Object() interface{}
|
||||
}
|
||||
|
||||
// URL defines an interface for HTTP request url.
|
||||
URL interface {
|
||||
SetPath(string)
|
||||
Path() string
|
||||
@ -58,6 +63,7 @@ type (
|
||||
Object() interface{}
|
||||
}
|
||||
|
||||
// Config defines engine configuration.
|
||||
Config struct {
|
||||
Address string
|
||||
TLSCertfile string
|
||||
|
@ -137,9 +137,7 @@ func WrapMiddleware(h fasthttp.RequestHandler) echo.MiddlewareFunc {
|
||||
return func(next echo.Handler) echo.Handler {
|
||||
return echo.HandlerFunc(func(c echo.Context) error {
|
||||
ctx := c.Request().Object().(*fasthttp.RequestCtx)
|
||||
if !c.Response().Committed() {
|
||||
h(ctx)
|
||||
}
|
||||
h(ctx)
|
||||
return next.Handle(c)
|
||||
})
|
||||
}
|
||||
|
@ -132,16 +132,16 @@ func WrapHandler(h http.Handler) echo.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// WrapMiddleware wraps `http.Handler` into `echo.MiddlewareFunc`
|
||||
func WrapMiddleware(h http.Handler) echo.MiddlewareFunc {
|
||||
// WrapMiddleware wraps `func(http.Handler) http.Handler` into `echo.MiddlewareFunc`
|
||||
func WrapMiddleware(m func(http.Handler) http.Handler) echo.MiddlewareFunc {
|
||||
return func(next echo.Handler) echo.Handler {
|
||||
return echo.HandlerFunc(func(c echo.Context) error {
|
||||
return echo.HandlerFunc(func(c echo.Context) (err error) {
|
||||
w := c.Response().Object().(http.ResponseWriter)
|
||||
r := c.Request().Object().(*http.Request)
|
||||
if !c.Response().Committed() {
|
||||
h.ServeHTTP(w, r)
|
||||
}
|
||||
return next.Handle(c)
|
||||
m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
err = next.Handle(c)
|
||||
})).ServeHTTP(w, r)
|
||||
return
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,4 @@ menu:
|
||||
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/crud)
|
||||
### [Source Code]({{< source "crud" >}})
|
||||
|
@ -9,12 +9,12 @@ menu:
|
||||
|
||||
### With go.rice
|
||||
|
||||
`rice.go`
|
||||
`main.go`
|
||||
|
||||
{{< embed "embed-resources/rice.go" >}}
|
||||
{{< embed "embed-resources/main.go" >}}
|
||||
|
||||
### Maintainers
|
||||
|
||||
- [caarlos0](https://github.com/caarlos0)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/rice)
|
||||
### [Source Code]({{< source "embed-resources" >}})
|
||||
|
@ -36,9 +36,9 @@ if _, err = io.Copy(dst, file); err != nil {
|
||||
|
||||
### Server
|
||||
|
||||
`server.go`
|
||||
`main.go`
|
||||
|
||||
{{< embed "file-upload/server.go" >}}
|
||||
{{< embed "file-upload/main.go" >}}
|
||||
|
||||
### Client
|
||||
|
||||
@ -50,4 +50,4 @@ if _, err = io.Copy(dst, file); err != nil {
|
||||
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/file-upload)
|
||||
### [Source Code]({{< source "file-upload" >}})
|
||||
|
@ -132,4 +132,4 @@ but is outside the scope of this recipe.
|
||||
|
||||
- [CaptainCodeman](https://github.com/CaptainCodeman)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/google-app-engine)
|
||||
### [Source Code]({{< source "google-app-engine" >}})
|
||||
|
@ -8,15 +8,15 @@ menu:
|
||||
|
||||
### With [grace](https://github.com/facebookgo/grace)
|
||||
|
||||
`server.go`
|
||||
`main.go`
|
||||
|
||||
{{< embed "graceful-shutdown/grace/server.go" >}}
|
||||
{{< embed "graceful-shutdown/grace/main.go" >}}
|
||||
|
||||
### With [graceful](https://github.com/tylerb/graceful)
|
||||
|
||||
`server.go`
|
||||
`main.go`
|
||||
|
||||
{{< embed "graceful-shutdown/graceful/server.go" >}}
|
||||
{{< embed "graceful-shutdown/graceful/main.go" >}}
|
||||
|
||||
### Maintainers
|
||||
|
||||
@ -24,6 +24,5 @@ menu:
|
||||
|
||||
### Source Code
|
||||
|
||||
[graceful](https://github.com/vishr/echo-recipes/blob/master/v2/graceful-shutdown/graceful)
|
||||
|
||||
[grace](https://github.com/vishr/echo-recipes/blob/master/v2/graceful-shutdown/grace)
|
||||
- [graceful]({{< source "graceful-shutdown/graceful" >}})
|
||||
- [grace]({{< source "graceful-shutdown/grace" >}})
|
||||
|
@ -16,4 +16,4 @@ menu:
|
||||
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/hello-world)
|
||||
### [Source Code]({{< source "hello-world" >}})
|
||||
|
@ -24,4 +24,4 @@ JSONP is a method that allows cross-domain server calls. You can read more about
|
||||
|
||||
- [willf](https://github.com/willf)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/jsonp)
|
||||
### [Source Code]({{< source "jsonp" >}})
|
||||
|
@ -18,11 +18,11 @@ expects the token to be present in an Authorization HTTP header using the method
|
||||
or even the request body. We will use the HS236 signing method, note that several
|
||||
other algorithms are available.
|
||||
|
||||
`server.go`
|
||||
`main.go`
|
||||
|
||||
{{< embed "jwt-authentication/server.go" >}}
|
||||
{{< embed "jwt-authentication/main.go" >}}
|
||||
|
||||
Run `server.go` and making a request to the root path `/` returns a 200 OK response,
|
||||
Run `main.go` and making a request to the root path `/` returns a 200 OK response,
|
||||
as this route does not use our JWT authentication middleware. Sending requests to
|
||||
`/restricted` (our authenticated route) with either no Authorization header or invalid
|
||||
Authorization headers / tokens will return 401 Unauthorized.
|
||||
@ -55,4 +55,4 @@ $ curl localhost:1323/restricted -H "Authorization: Bearer <token>" => Access g
|
||||
|
||||
- [axdg](https://github.com/axdg)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/jwt-authentication)
|
||||
### [Source Code]({{< source "jwt-authentication" >}})
|
||||
|
@ -17,4 +17,4 @@ menu:
|
||||
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/middleware)
|
||||
### [Source Code]({{< source "middleware" >}})
|
||||
|
@ -11,9 +11,9 @@ menu:
|
||||
|
||||
### Server
|
||||
|
||||
`server.go`
|
||||
`main.go`
|
||||
|
||||
{{< embed "streaming-file-upload/server.go" >}}
|
||||
{{< embed "streaming-file-upload/main.go" >}}
|
||||
|
||||
### Client
|
||||
|
||||
@ -25,4 +25,4 @@ menu:
|
||||
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/streaming-file-upload)
|
||||
### [Source Code]({{< source "streaming-file-upload" >}})
|
||||
|
@ -11,9 +11,9 @@ menu:
|
||||
|
||||
### Server
|
||||
|
||||
`server.go`
|
||||
`main.go`
|
||||
|
||||
{{< embed "streaming-response/server.go" >}}
|
||||
{{< embed "streaming-response/main.go" >}}
|
||||
|
||||
### Client
|
||||
|
||||
@ -35,4 +35,4 @@ $ curl localhost:1323
|
||||
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/streaming-response)
|
||||
### [Source Code]({{< source "streaming-response" >}})
|
||||
|
@ -3,16 +3,16 @@ title: Subdomains
|
||||
menu:
|
||||
side:
|
||||
parent: recipes
|
||||
weight: 10
|
||||
weight: 10
|
||||
---
|
||||
|
||||
`server.go`
|
||||
`main.go`
|
||||
|
||||
{{< embed "subdomains/server.go" >}}
|
||||
{{< embed "subdomains/main.go" >}}
|
||||
|
||||
### Maintainers
|
||||
|
||||
- [axdg](https://github.com/axdg)
|
||||
- [vishr](https://github.com/axdg)
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/subdomains)
|
||||
### [Source Code]({{< source "subdomains" >}})
|
||||
|
@ -10,7 +10,7 @@ menu:
|
||||
|
||||
`server.go`
|
||||
|
||||
{{< embed "website/server.go" >}}
|
||||
{{< embed "website/main.go" >}}
|
||||
|
||||
### Client
|
||||
|
||||
@ -22,4 +22,4 @@ menu:
|
||||
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/website)
|
||||
### [Source Code]({{< source "website" >}})
|
||||
|
@ -10,7 +10,7 @@ menu:
|
||||
|
||||
`server.go`
|
||||
|
||||
{{< embed "websocket/server.go" >}}
|
||||
{{< embed "websocket/main.go" >}}
|
||||
|
||||
### Client
|
||||
|
||||
@ -44,4 +44,4 @@ Hello, Server!
|
||||
|
||||
- [vishr](https://github.com/vishr)
|
||||
|
||||
### [Source Code](https://github.com/vishr/echo-recipes/blob/master/v2/websocket)
|
||||
### [Source Code]({{< source "websocket" >}})
|
||||
|
@ -1,2 +1,2 @@
|
||||
<pre data-src="https://raw.githubusercontent.com/vishr/echo-recipes/master/v2/{{ .Get 0 }}">
|
||||
<pre data-src="https://raw.githubusercontent.com/labstack/echox/master/recipe/{{ .Get 0 }}">
|
||||
</pre>
|
||||
|
1
website/layouts/shortcodes/source.html
Normal file
1
website/layouts/shortcodes/source.html
Normal file
@ -0,0 +1 @@
|
||||
https://github.com/labstack/echox/tree/master/recipe/{{ .Get 0 }}
|
Loading…
x
Reference in New Issue
Block a user