<p>Hello everyone.</p>
<p>I've been writing some code that makes quick and dirty http requests and I realised my code is brittle because it will error if any request fails even once.</p>
<p>What are some simple 'ways' I can use exponential back off when making http requests?
Can I do it with the standard lib (in an opaque manner)? Do I need a thin library?
How have you done it in practice? </p>
<p>Cheers!</p>
<hr/>**评论:**<br/><br/>wilywes: <pre><p>My favourite library for this is <a href="https://github.com/sethgrid/pester" rel="nofollow">Pester </a>. There's a few others and it's simple enough that you could use the stdlib (pester has no dependencies). </p></pre>bmurphy1976: <pre><p>I wrote this a couple years back and we use it in some of our software. It doesn't support jitter or alternative backoff algorithms like the the library <a href="/u/wilywes" rel="nofollow">/u/wilywes</a> posted, but it's a bit more generic and useful in other situations:</p>
<p><a href="https://github.com/mediafly/retry" rel="nofollow">https://github.com/mediafly/retry</a></p>
<p>Could probably use some polish but it gets the job done. </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传