Yet another GOPATH question

xuanbao · · 515 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey guys, New to using Go. Trying to use it when Node just isn&#39;t needed. Creating a small back-end &#34;get&#34; restful call to an JSON API with Go that works with a Backbone front-end. Do i need to make yet another path? Or store the Go file in my original go path? Or can i store the Go file with everything else in my app. Sorry for being such a noob. This just confused me a little.</p> <hr/>**评论:**<br/><br/>dchapes: <pre><p>Have you read <a href="https://golang.org/doc/code.html#Workspaces" rel="nofollow">How to Write Go Code</a>?</p></pre>upboatact: <pre><p>also <a href="http://gowithconfidence.tumblr.com/post/118493925546/getting-started-with-go-workspaces" rel="nofollow">http://gowithconfidence.tumblr.com/post/118493925546/getting-started-with-go-workspaces</a> to understand the whole GOPATH deal</p></pre>r_y_m_a_t: <pre><p>thanks a lot! trying to read as much as i possibly can</p></pre>justinisrael: <pre><p>When you refer to it as the &#34;go file&#34; it sounds like you are thinking of it as one file you want to throw into a location and build specifically, instead of thinking of it as a package (one or more files). The go tool can build packages by name, in which case the GOPATH is consulted to find that package. Otherwise you would have to &#34;go build&#34; the absolute file path. So for building a package, you could symlink the Go package to your GOPATH, or check out the whole project to your GOPATH in the first place, or go build the single file directly, or use the &#34;gb&#34; to as alternative, which relies on directory structures and not GOPATH </p></pre>r_y_m_a_t: <pre><p>I have a GOPATH set up in a $HOME/go_work folder. I come from a Node.js environment where it was easy to just have a server.js file running with Express within your Backbone set up. Is this not the case with Go? If i write the RESTFUL server in Go, but in the go_work folder where my source code lives, how do i link that with Backbone. Thats really been my issue. I am enjoying working with Go and have been fascinated with what it can do, I&#39;m just struggling making sure everything is in its proper place. </p></pre>justinisrael: <pre><p>The Go tool depends on the GOPATH as the place for it to resolve all imports of your code and dependencies. This is instead of needing a description file or a Makefile, and is just what they chose to do. So if you use the Go tool, you can either link it to your GOPATH, or run &#34;go build&#34; on that specific file in your project area. Or you can switch to building with gb instead. Basically there are options, and you can achieve the equivalent of your Node experience, in being able to build your server application in that subdirectory of your project. </p></pre>r_y_m_a_t: <pre><p>Thanks for sharing GB. Running on a project to project basis seems like an easier option especially when using Go for the purpose of a RESTFUL backend and having everything in one Git repo to be able to share and fork. I think I&#39;m going to go in that direction. </p></pre>

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

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