What are the built in go tools what are they used for?

xuanbao · · 483 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>So I started learning Go about a year ago. I only use it for pet projects here and there so I&#39;m by no means a power user. I&#39;m familiar with a few of the build in tools like <code>build</code>, <code>run</code>, and <code>test</code>, but I only know they&#39;re basic functionality and have no idea how some tools like <code>generate</code> work. I feel like I&#39;m missing out on some pretty powerful work flows by not understanding what these tools can do. Can anyone shed some light on some cool/powerful ways to use these tools?</p> <hr/>**评论:**<br/><br/>earthboundkid: <pre><p>I wrote <a href="https://blog.carlmjohnson.net/post/2016-11-27-how-to-use-go-generate/" rel="nofollow">a blog post about go:generate</a> recently.</p></pre>adamryman: <pre><p>So I believe in helping by teaching to fish.</p> <p>On your command line try</p> <pre><code>go -h </code></pre> <p>You will see a list of built commands:</p> <pre><code>build compile packages and dependencies clean remove object files doc show documentation for package or symbol env print Go environment information fix run go tool fix on packages fmt run gofmt on package sources generate generate Go files by processing source get download and install packages and dependencies install compile and install packages and dependencies list list packages run compile and run Go program test test packages tool run specified go tool version print Go version vet run go tool vet on packages </code></pre> <p>Out of these, fmt and vet are very useful. fmt will format your code and vet will tell you if you have basic problems with your code.</p> <p>Now you can try</p> <pre><code>go help vet </code></pre> <p>or</p> <pre><code>go help generate </code></pre> <p>Other really useful tools out there that are not built in but are highly recommend are:</p> <p>GoRename - Rename something throughout your workspace. Your code will compile after still or the rename will not happen and you will get a useful error</p> <p><a href="https://godoc.org/golang.org/x/tools/cmd/gorename" rel="nofollow">https://godoc.org/golang.org/x/tools/cmd/gorename</a></p> <p>GoImports - Fix your imports automatically</p> <p><a href="https://godoc.org/golang.org/x/tools/cmd/goimports" rel="nofollow">https://godoc.org/golang.org/x/tools/cmd/goimports</a></p> <p>Go Guru - tell you tons of stuff about your code</p> <p><a href="https://docs.google.com/document/d/1_Y9xCEMj5S-7rv2ooHpZNH15JgRT5iM742gJkw5LtmQ/edit" rel="nofollow">https://docs.google.com/document/d/1_Y9xCEMj5S-7rv2ooHpZNH15JgRT5iM742gJkw5LtmQ/edit</a></p> <p>I use all of these tools integrated into my editor, vim, with vim-go.</p> <p><a href="https://github.com/fatih/vim-go" rel="nofollow">https://github.com/fatih/vim-go</a></p> <p>Though they are all just command line tools that you don&#39;t need any editor to use.</p> <p>The tooling in golang is amazing, it has spoiled me from most other languages at this point.</p></pre>Destructicorn: <pre><p>Thanks for the feedback. I&#39;ve looked at <code>go -h</code> before but wasn&#39;t sure which of those tools I should be using. I&#39;ll for sure start exploring more.</p></pre>

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

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