<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's not.</p>
<p>However, if you're using git, you can perform a git "insteadOf" 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'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't need me :)</p></pre>