Is it possible to write go modular code like NodeJs does?

blov · · 482 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m looking to see if there&#39;s any workarounds for importing local go packages without dealing with gopath or go project structures. Someting like node_modules and require does, but for go. Thanks!</p> <hr/>**评论:**<br/><br/>rangeCheck: <pre><p>vgo is mostly what you want (it needs gopath currently but that&#39;s &#34;hidden&#34; behind the scene and could use default value if you don&#39;t do anything)</p> <p>vendoring doesn&#39;t need gopath, but you need some local path structure</p></pre>unix15e8: <pre><p>Packages are not required to be in the GOPATH in order to be imported. Whenever I need to import packages into my local directory, I just do something like <code>export GOPATH=$(pwd)</code> and continue working as if nothing had happened. Three new directories will be created: bin, pkg, src as described here [1]. Having your packages in GOPATH is just something &#34;nice to have&#34; because the majority of tools and IDEs out there assume your packages are there, but I have been working like this <em>(with the local GOPATH)</em> for +4 years now and haven&#39;t found any difference.</p> <p>[1] <a href="https://golang.org/doc/code.html#remote" rel="nofollow">https://golang.org/doc/code.html#remote</a></p></pre>danredux: <pre><p>Go 1.8+ doesn&#39;t need GOPATH.</p> <p>Also, generally, you don&#39;t need to care where the packages are. What issue are you running in to that you actually want to fix? &#34;go get x.com/pkg&#34; makes the package available, why are you concerned with it&#39;s final resting place?</p></pre>

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

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