mirror of
https://github.com/labstack/echo.git
synced 2025-04-19 12:12:51 +02:00
parent
0163cddab5
commit
f09efac326
16
echo.go
16
echo.go
@ -463,7 +463,21 @@ func (e *Echo) Routes() []Route {
|
|||||||
|
|
||||||
// ServeHTTP implements `http.Handler` interface, which serves HTTP requests.
|
// ServeHTTP implements `http.Handler` interface, which serves HTTP requests.
|
||||||
func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
e.router.ServeHTTP(w, r)
|
c := e.pool.Get().(*Context)
|
||||||
|
h, e := e.router.Find(r.Method, r.URL.Path, c)
|
||||||
|
c.reset(r, w, e)
|
||||||
|
|
||||||
|
// Chain middleware with handler in the end
|
||||||
|
for i := len(e.middleware) - 1; i >= 0; i-- {
|
||||||
|
h = e.middleware[i](h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute chain
|
||||||
|
if err := h(c); err != nil {
|
||||||
|
e.httpErrorHandler(err, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
e.pool.Put(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server returns the internal *http.Server.
|
// Server returns the internal *http.Server.
|
||||||
|
16
router.go
16
router.go
@ -398,18 +398,10 @@ End:
|
|||||||
|
|
||||||
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
c := r.echo.pool.Get().(*Context)
|
c := r.echo.pool.Get().(*Context)
|
||||||
h, e := r.Find(req.Method, req.URL.Path, c)
|
h, _ := r.Find(req.Method, req.URL.Path, c)
|
||||||
c.reset(req, w, e)
|
c.reset(req, w, r.echo)
|
||||||
|
|
||||||
// Chain middleware with handler in the end
|
|
||||||
for i := len(e.middleware) - 1; i >= 0; i-- {
|
|
||||||
h = e.middleware[i](h)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute chain
|
|
||||||
if err := h(c); err != nil {
|
if err := h(c); err != nil {
|
||||||
e.httpErrorHandler(err, c)
|
r.echo.httpErrorHandler(err, c)
|
||||||
}
|
}
|
||||||
|
r.echo.pool.Put(c)
|
||||||
e.pool.Put(c)
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,28 @@ menu:
|
|||||||
Use `req.ParseMultipartForm(16 << 20)` for manually parsing multipart form. It gives
|
Use `req.ParseMultipartForm(16 << 20)` for manually parsing multipart form. It gives
|
||||||
us an option to specify the maximum memory used while parsing the request body.
|
us an option to specify the maximum memory used while parsing the request body.
|
||||||
|
|
||||||
|
If you just want to upload a single file:
|
||||||
|
|
||||||
|
```go
|
||||||
|
file, fh, err := req.FormFile("file")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
// Destination
|
||||||
|
dst, err := os.Create(fh.Filename)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer dst.Close()
|
||||||
|
|
||||||
|
// Copy
|
||||||
|
if _, err = io.Copy(dst, file); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Server
|
### Server
|
||||||
|
|
||||||
`server.go`
|
`server.go`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user