Where to put “defer req.Body.Close()”?

前端 未结 5 786
你的背包
你的背包 2021-01-01 15:25

I have net/http handlers that have defer req.Body.Close() in each on web server side.

What is the correct place to put this in? Should I pu

5条回答
  •  孤城傲影
    2021-01-01 16:02

    According to the Go documentation it is up to you to close the body once you are done with it.

    I usually put the defer line right after the line where I check the request for errors.

提交回复
热议问题