<p>I'm noobie to Golang. Now I'm working on my university project and it's becoming more complicated so I wanted to split code between several files.
1) Is there a way to create directory with some modules like in python:
import "./dir/some_module"
2) Is there any programs that creates virtualenv like in python.</p>
<hr/>**评论:**<br/><br/>programfog: <pre><p><a href="http://stackoverflow.com/a/15051192/275583" rel="nofollow">http://stackoverflow.com/a/15051192/275583</a></p></pre>peterbourgon: <pre><p>To clarify, the first answer to that question is correct, i.e. you should (must) always import the fully-qualified path of a package, e.g. <code>github.com/yourname/yourrepo/mypkg</code>. </p>
<p>The second answer is incorrect, i.e. you shouldn't (can't) import in a relative sense, e.g. <code>./mypkg</code>. </p></pre>luminoumen: <pre><p>but if, for example, project will move from github to bitbucket I need to fix all imports?</p></pre>PsyWolf: <pre><p>Yes, but with Go the whole process is as easy as </p>
<p><code>gofmt -w -r '"github.com/foo/bar" -> "bitbucket.com/foo/bar"' *.go</code></p>
<p>(Note that the whole argument to -r is in single quotes, with double quotes inside it.) </p>
<p>From <a href="https://groups.google.com/forum/m/#!topic/golang-nuts/RyhFfhB_kd8" rel="nofollow">this golang-nuts thread</a></p></pre>PsyWolf: <pre><p>Alternatively, if you really need a level of indirection, check out <a href="https://texlution.com/post/golang-canonical-import-paths" rel="nofollow">vanity and canonical import paths</a>. It's overkill for most people, but if you actually expect to change repo hosting, that's how the go team managed their move away from code.google.com</p></pre>luminoumen: <pre><p>Imagine I changed github->bitbucket. So, I can't event build my project before I commit my changes to bitbucket? How you live with this, people?</p></pre>KenjiTakahashi: <pre><blockquote>
<p>Imagine I changed github->bitbucket. So, I can't event build my project before I commit my changes to bitbucket?</p>
</blockquote>
<p>You don't have to commit anything to do the build. Just move the project to proper path(s) in your $GOPATH.</p>
<blockquote>
<p>How you live with this, people?</p>
</blockquote>
<p>We don't throw our projects around.</p></pre>joushou: <pre><p>You should instead be whining about "What if I fork a popular project on github, and it won't build because the import paths include the username?"</p>
<p>It sucks, yeah, but <em>other than that</em>, the system actually works kind of well.</p></pre>peterbourgon: <pre><p>Yes. (Or use a vanity import path, if you own a domain.)</p>
<p>In practice, I think this has happened approximately never.</p></pre>KenjiTakahashi: <pre><p>I've seen it happen once when googlecode shat down.</p></pre>TheMerovius: <pre><p>If your project moves from github to bitbucket, it becomes a different package (as packages are identified by their import paths). This is a feature, not a bug.
If you don't want a different entity to own your package name (because that's what's effectively the case, when your package name begins with <code>github.com</code> or <code>bitbucket.org</code>), use a vanity import path.</p></pre>k_u_r_o_k_u_s_e: <pre><blockquote>
<p>If your project moves from github to bitbucket, it becomes a different package</p>
</blockquote>
<p>this. How is it so hard to understand. go "packages as URI" have a few problems , but this is certainly not an issue. </p>
<p>1 URI = 1 package , end of story.</p></pre>luminoumen: <pre><p>This answer didn't work for me. Can you please clarify it for me. If I have 3 lib files and one main. Then I move 3 lib files to directory named lib/ then how to make it work?</p></pre>k_u_r_o_k_u_s_e: <pre><p>If you move 3 packages into a different directory then they are different packages, not the same.</p></pre>luminoumen: <pre><p>My repo <a href="https://github.com/luminousmen/Master" rel="nofollow">https://github.com/luminousmen/Master</a></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传