使用Hashcorp的cleanhttp
缘起 早上在某地方看到这样一张图 大意是说任何第三方库都可以拦截您的所有 HTTP 调用,然后推荐了一个库 cleanhttp 官网的介绍: Functions for accessing “clean” Go http.Client values 用于访问“干净”Go http.Client 值的函数 The Go standard library contains a default http.Client called http.DefaultClient. It is a common idiom in Go code to start with http.DefaultClient and tweak it as necessary, and in fact, this is encouraged; from the http package documentation: Go 标准库包含一个名为 http.DefaultClient 的默认 http.Client 。在 Go 代码中,以 http.DefaultClient 开头并根据需要进行调整是一种常见的习惯用法,事实上,这是值得鼓励的;来自 http 包文档: The Client’s Transport typically has internal state (cached TCP connections), so Clients should be reused instead of created as needed....