Help us understand the problem. What is going on with this article?

Golangでhttp.getをリトライする

More than 1 year has passed since last update.

再帰処理をしてリトライする。

リトライ数が増えるたびに10秒タイムアウトを伸ばす

main.go
func HttpGet(url string, reTry int) *http.Response,error {
    client := &http.Client{Timeout: time.Duration(10*(10-reTry)) * time.Second}
    resp, err := client.Get(url)
    if err != nil {
        if reTry == 0 {
            return nil,error
        }
        return HttpGet(url, reTry-1)
    }
}

PS.再帰処理ってほとんど有用性無いような気がするのは俺だけ?

Azunyan1111
#seccamp 18 18Y 16F/Golang/Webセキュリティ/サイバー犯罪/Tor研究&Torサービス運営/ゲーム会社
https://blog.azunyan1111.com/
naxa
動画関連サービスの技術支援、開発、コンサルティングを行っています。
https://www.naxa.co.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away