How to release http.Client in Go?

前端 未结 2 1700
青春惊慌失措
青春惊慌失措 2020-12-10 08:03

I built a http.Client for HTTP2 connection, what do I need to do to release the client and resource used?

2条回答
  •  忘掉有多难
    2020-12-10 08:30

    The CloseIdleConnections() method was added in Go 1.12.

    https://golang.org/pkg/net/http/#Client.CloseIdleConnections

    CloseIdleConnections closes any connections on its Transport which were previously connected from previous requests but are now sitting idle in a "keep-alive" state. It does not interrupt any connections currently in use.

提交回复
热议问题