<p>I'm just started learning programming. I'm curious to know. How do I know when to use a certain packages ? </p>
<hr/>**评论:**<br/><br/>shovelpost: <pre><p>It depends on what your program tries to do.</p>
<p>Say for example that you need to find if a string contains a certain character or phrase. You probably don't want to write that algorithm yourself and most languages offer it on their standard library. Go does as well with <a href="https://golang.org/pkg/strings/#Contains" rel="nofollow">strings.Contain</a>. So in this case you have to use the <a href="https://golang.org/pkg/strings/" rel="nofollow"><code>strings</code></a> package.</p>
<p>Say you wanted to convert a string to an integer, then you will need the <a href="https://golang.org/pkg/strconv/" rel="nofollow"><code>strconv</code></a> package.</p>
<p>If you want to write a web application you will need the <a href="https://golang.org/pkg/net/http/" rel="nofollow"><code>net/http</code></a>.</p>
<p>Need to work with a database? There's <a href="https://golang.org/pkg/database/sql/" rel="nofollow"><code>database/sql</code></a>.</p>
<p>Need to work with JSON? there's <a href="https://golang.org/pkg/encoding/json/" rel="nofollow"><code>encoding/json</code></a>.</p>
<p>And the list goes on.</p>
<p>Just focus on what you want your program to achieve and eventually you will find out which packages you need. Google is your friend and you can always ask a more specific question here or at the <a href="https://forum.golangbridge.org/" rel="nofollow">bridge forum</a>.</p></pre>dlsniper: <pre><p>Or on the Slack channel <a href="https://invite.slack.golangbridge.org/" rel="nofollow">https://invite.slack.golangbridge.org/</a></p></pre>mocara: <pre><p>Thanks for that. Had no idea that forum existed and it's great. :) </p></pre>snippet2: <pre><p>You have to try them out. It's the only way to learn any. The most popular beginner one is bufio <a href="https://godoc.org/bufio" rel="nofollow">https://godoc.org/bufio</a></p>
<p>Go core <a href="https://golang.org/pkg" rel="nofollow">https://golang.org/pkg</a></p>
<p>Most popular <a href="https://godoc.org" rel="nofollow">https://godoc.org</a></p>
<p>Wiki list <a href="https://github.com/golang/go/wiki/Projects" rel="nofollow">https://github.com/golang/go/wiki/Projects</a></p></pre>aRegularFarmChicken: <pre><p>I'm new to Go too. In web development at least, I google the problem, along with the language I am programming in. It should return the snippet you need and link to the required library. In php, for example, there is usually a function for it. </p></pre>okawei: <pre><p>This is a very broad question. Like another user said just pull in a package and see if it fits your use case. Also, if you're trying to solve a very common problem (I.e connecting to a database, processing credit cards, processing images etc) look for a package to do it for you</p></pre>copesc: <pre><p>It all comes down to experience, the more you'll use packages, the more you'll know which ones to use, which ones to avoid.. without that, asking here or forum or slack is the optimal way to see what people would use in that specific use case.</p>
<p>I rely a lot on <a href="https://godoc.org" rel="nofollow">https://godoc.org</a>, and stars and imports offer the way to determine the actual package usage.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传