Import Question

agolangf · · 494 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Is it possible to specify a port, not just a URL when doing remote imports?</p> <p>I have an environment where this is almost mandatory and cannot seem to figure out the magic sauce.</p> <p>Thanks,</p> <hr/>**评论:**<br/><br/>danredux: <pre><p>No it&#39;s not.</p> <p>However, if you&#39;re using git, you can perform a git &#34;insteadOf&#34; to change the url (and port) that git uses to fetch the package.</p></pre>tundra: <pre><p>Right, I was aware of that workaround.</p> <p>Is there some reason ports are not supported in the import URL formation rules? A good many private dev shops (including the one in question here) run their own git, nexus, etc. repos. It seems like having this ability would be really helpful, and not having it seems to be no advantage.</p></pre>darkskiez: <pre><p>Mono repo for everything; or submodules in your own namespace; or private internal git https server.. not sure how the ports thing would help.</p></pre>drvd: <pre><blockquote> <p>Is there some reason ports are not supported in the import URL formation rules?</p> </blockquote> <p>Yes, there is! Imports are not URLs. Really, they are not. Import statements as far as the <em>compiler</em> is concerned are just strings naming object files to import. Common sense and the tooling like to go tool make them file paths. See <a href="https://golang.org/cmd/go/#hdr-Import_path_syntax" rel="nofollow">https://golang.org/cmd/go/#hdr-Import_path_syntax</a> .</p> <p>Do not mix up the import with what <code>go get</code> does: <code>go get</code> uses <em>convention</em> that package paths may start with a domain name and <code>go get</code> has some built knowhow about well-known code hosting sites and how to git clone or hg clone or bzr clone/branch/whetever a remote repository. Remember: Package paths <em>are</em> <em>not</em> <em>URLs</em>.</p> <p>But <code>go get</code> is clever and can do more: Read <a href="https://golang.org/cmd/go/#hdr-Remote_import_paths" rel="nofollow">https://golang.org/cmd/go/#hdr-Remote_import_paths</a> for details. You might even recompile the go tool and bake your knowledge about your specific code hosting site into the tool.</p> <p>But please do not think of import paths as URLs.</p></pre>mrfrobozz: <pre><p>I think ports may not be allowed because they end up using the URL as a path on the file system and not all file systems work with colons.</p></pre>tundra: <pre><p>Seems like a poor reason to not support this. The fact is that most of my clients are not using public facing git repos and servers. They&#39;re running them internally on all manner of ports other than 80 or 443.</p> <p>Oh well, onward ... if this stuff were easy, they wouldn&#39;t need me :)</p></pre>

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

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