<p>Hi! I've recently started learning go by submitting PRs to projects that I had an interest in, and felt I'd seen enough to start my own. I've put together this set of <a href="https://github.com/jangie/goloadbalancers" rel="nofollow">loadbalancer algorithms</a> as a result along with some tests. As I don't do this kind of stuff at work, I'd love to have some comments as to whether this looks like 'proper' go and for anything else you can think of!</p>
<hr/>**评论:**<br/><br/>driusan: <pre><p>I just had a quick look at the main server.go, and it's not bad for a first stab at Go, but there's a few minor nits:</p>
<ol>
<li>Why are you import/discarding "net/http/pprof"?</li>
<li>You're discarding errors instead of handling them. Instead of returning <em>testHarness, you could return (</em>testHarness, error) and then return the err where applicable instead of ignoring it.</li>
<li><p>Code like this is unnecessary:</p>
<p>var tdrr = testHarness{
next: rebalancer,
port: 8096,
}
return &tdrr</p></li>
</ol>
<p>You can just do:</p>
<pre><code>return &testHarness{
next: rebalancer,
port: 8096,
}
</code></pre>
<ol>
<li>You're not consistent with if you range through the balancees and then return a *testHarness, or declare a *testHarness and then range through the balancees, then return the *testHarness in getRoundRobinHarness/getDynamicRoundRobinHarness.</li>
</ol></pre>skidooer: <pre><blockquote>
<p>Why are you import/discarding "net/http/pprof"?</p>
</blockquote>
<p>Probably because that is how it is meant to be used: <a href="https://golang.org/pkg/net/http/pprof/" rel="nofollow">https://golang.org/pkg/net/http/pprof/</a></p></pre>jangiegb: <pre><p>2 I'll make sure to propagate errors up!
3 is dumb of me, I'll take care of that.</p>
<p>I'll also take care of the inconsistencies, thanks!</p></pre>alexflint: <pre><p>Looks like very clean code imho. In jsq.go line 120-121, it's quite common to instead use</p>
<pre><code>http.Error(w, http.StatusBadGateway, "msg...")
</code></pre></pre>jangiegb: <pre><p>Ooo, I haven't seen that before, will be changing, thanks!</p></pre>alexflint: <pre><p>Personally I would have the balancer constructors take in a <code>[]url.URL</code> rather than <code>[]string</code> since then you can handle any URL parsing errors outside the constructors. Another option would be to have the constructors return errors, but I think it's always nice to have functions that can't fail (and hence do not need error return values).</p></pre>jangiegb: <pre><p>Good call! I'll be changing those tonight hopefully :)</p></pre>kpurdon: <pre><p>You should also check out the <a href="https://invite.slack.golangbridge.org/" rel="nofollow">gophers slack</a> specifically the #reviews channel. </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传