Extract useful contents from a HTML page. My first Go app

polaris · · 402 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi all,</p> <p>I decided to learn programming with Go. I would like to make my first app something useful for community. </p> <p>So, i created the package &#34;articletext&#34; to extract useful (primary) content text from a html page. A function analyses a html code and drops everything related to navigation, advertising etc. Extracts only useful contents of a document, text of a central element.</p> <p>But, i am more interested in your feedback about a programming style. What mistakes did i do? What can be done better in terms of code organization, commenting and &#34;best practices&#34;?</p> <p>There is my package <a href="https://github.com/Gelembjuk/articletext" rel="nofollow">https://github.com/Gelembjuk/articletext</a></p> <hr/>**评论:**<br/><br/>mwholt: <pre><p>Nice job!</p> <p>I&#39;d suggest writing some tests. <a href="https://golang.org/pkg/testing" rel="nofollow">https://golang.org/pkg/testing</a> will help with that.</p> <p>I&#39;d also suggest looking at the lint warnings; learn to conform to godoc specifications. Here are the lint warnings: <a href="https://goreportcard.com/report/github.com/Gelembjuk/articletext" rel="nofollow">https://goreportcard.com/report/github.com/Gelembjuk/articletext</a></p> <p><a href="https://github.com/Gelembjuk/articletext/blob/2023e034759d51e7466c18a80eaf40146aedd81b/articletext.go#L48-L49" rel="nofollow">These error handling lines</a> should lose the log.Fatal, which terminates the program.</p></pre>beertocode: <pre><p>A good way to have a quick check on your code is to use go report card: <a href="https://goreportcard.com/report/github.com/Gelembjuk/articletext" rel="nofollow">https://goreportcard.com/report/github.com/Gelembjuk/articletext</a></p> <p>Better: Use golint or better gometalinter everytime before you commit new code.</p> <p>Handle errors gracefully. You are using <code>log.Fatal</code> in most error conditions, which will exit the program immediately, instead of returning the error.</p></pre>

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

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