first golang (mini) app, code reviews wanted!

agolangf · · 392 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi, started playing with go and made a very simple pypi server (web server thar hosts python package repository).</p> <p><a href="https://github.com/msf/go-minipypi" rel="nofollow">https://github.com/msf/go-minipypi</a></p> <p>Hi All, this is my first app in golang and I&#39;m looking for codereviews to improve style, naming and code layout. Basically make it a higher quality (but frugal) Go app. The functional features are somewhat secondary.. but fair game too. Currently it is a bit low quality, for example, I haven&#39;t done unit tests which is at the top of my list.</p> <p>any review is wanted, thanks for your time and patience!</p> <p>Thanks in advance</p> <hr/>**评论:**<br/><br/>jeffrallen: <pre><p>Filenames are usually lowercase.</p> <p>This is not idiomatic (i.e. good Go code is tested): $ ls *_test.go ls: *_test.go: No such file or directory</p> <p>Good use of interface FileFetcher. Each implementation of FileFetcher should have a line that does the compile-time check that the interface is correctly implemented. This is useful documentation for the reader, it says, &#34;look, this is important, this is one kind of FileFetcher&#34;. <a href="https://splice.com/blog/golang-verify-type-implements-interface-compile-time/" rel="nofollow">https://splice.com/blog/golang-verify-type-implements-interface-compile-time/</a></p> <p>Good job not ignoring errors.</p> <p>Why is it not designed from the get-go for HTTPS? HTTP is old, bad news. A TLS connection might be able to negotiate HTTP/2, depending on the client, which can get you all kinds of goodness. Not to mention, frustrate the NSA, which is a nice side benefit. (Unless you ARE the NSA... hmm.)</p> <p>frontend.go&#39;s globals &#34;fetcher&#34; and &#34;webServerConfigs&#34; are code smell. What if you wanted to have two servers in one address space, with two different fetchers? Globals should be very rare.</p> <p>It is rarely a good idea to write the whole thing in package main. From the first moment, write in a package, and make a subdir which is package main with a tiny bit of code to call into your package. Then as you add features decide if they go in the library or in the cmd. When someone wants to add your feature into their project, they won&#39;t curse you for putting everything in main.</p> <p>-jeff</p></pre>m3thos: <pre><p>Thanks a lot, will address this on the weekend</p></pre>m3thos: <pre><p>any tips ? :)</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

392 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传