<p>Hey guys,
New to using Go. Trying to use it when Node just isn't needed. Creating a small back-end "get" 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 "go file" 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 "go build" 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 "gb" 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'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 "go build" 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'm going to go in that direction. </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传