echo icon indicating copy to clipboard operation
echo copied to clipboard

On Contex#FromFile return the file descriptor (it's already open by Go stdlib)

Open pafuent opened this issue 4 years ago • 0 comments

Issue Description

Maybe in a future version of Echo, the return variables of Context#FormFile could be changed to return also the file descriptor, to avoid the cost of open it from multipart.FileHeader, which is already performed in Go net/http/request stdlib. The only advantage that I can see in the current signature of Context#FormFile is that the user is not responsible for closing the file descriptor, which reduces the cost of a File Descriptor leak vs opening the same file twice.

Checklist

  • [x] Dependencies installed
  • [x] No typos
  • [x] Searched existing issues and docs

Expected behaviour

The file descriptor obtained from net/http/request is return open, to avoid to reopen it later on in the caller function

Actual behaviour

The file descriptor obtained from net/http/request is Close() https://github.com/labstack/echo/blob/ad3be08de1d58a99644a72dd1a62a20d76d91ec1/context.go#L368 And that file needs to be open again by the caller of Context#FormFile

Related code

https://github.com/labstack/echo/blob/ad3be08de1d58a99644a72dd1a62a20d76d91ec1/context.go#L363-L370

https://github.com/golang/go/blob/78e59bb1f72c9cd16e204dbfeee05ae99a2462e3/src/net/http/request.go#L1364-L1381

pafuent avatar Nov 21 '20 01:11 pafuent