<p>We probably need a community supported mirror for packages.</p>
<p>Simplest way that I can think of goes something like this.</p>
<p>in Gopkg.toml, add source as the community maintained mirror, like so</p>
<p>```</p>
<p>[[constraint]]</p>
<p>name = "github.com/user/package"</p>
<p>source = "example.com/github.com/user/package"</p>
<p>version = "1.0.0"</p>
<p>```</p>
<p>here example.com redirects to <code>github.com/user/package</code> the first time, then caches in background and ensures all branches, commits and tags exist from that point on.</p>
<p>This still leaves two use cases:</p>
<ol>
<li><p>What about repos that haven't been requested ever?</p></li>
<li><p>What if someone gets hold of the username and updates the code?</p></li>
</ol>
<p>Also, how would we finance something this big?</p>
<hr/>**评论:**<br/><br/>pmrsaurus: <pre><p>Isn't the fix to simply <code>vendor/</code> your dependencies?</p></pre>TheMerovius: <pre><blockquote>
<p>in Gopkg.toml, add source as the community maintained mirror, like so</p>
</blockquote>
<p>That assumes there is a Gopkg.toml.</p>
<p>I don't think that requiring upstream cooperation has any chance of resulting in a successful design.</p>
<p>FWIW, I made a <a href="https://github.com/golang/go/issues/21292">proposal</a> a while back to add transparent support for mirrors to go-get. The idea is to simply put a GOPATH on a webserver (so, e.g. serve <a href="https://foobar.com/github.com/user/repo">https://foobar.com/github.com/user/repo</a>) and then have go-get make a request to <code><mirror-url>/<importpath></code> instead of <code>https://<importpath></code>, if a flag is given.</p>
<p>IMO it would be pretty simple to implement that today [edit](sorry, this was dropped) as a separate tool[/edit] and it would solve a whole lot of issues that other people are trying to solve with dep/vendoring/whatever. It would just need someone to actually do it (and be willing to host mirrors).</p></pre>jmank88: <pre><p>Related:</p>
<p><a href="https://github.com/whyrusleeping/gx/issues/141" rel="nofollow">Start a conversation about ipfs/gx-style imports in dep</a></p>
<p><a href="https://github.com/golang/dep/issues/286" rel="nofollow">Support for private/enterprise patterns</a></p></pre>freman: <pre><p>could just hack up a .gitconfig :D</p>
<pre><code>[url "https://172.31.3.81:9992/https/github.com"]
insteadOf = https://github.com
</code></pre>
<p>We're using it as a caching proxy but there's no reason you can'mt</p>
<pre><code>[url "https://example.com/github.com/user/package"]
insteadOf = https://github.com/user/package
</code></pre></pre>