improve redirection to canonical import path
Our GitHub organisation is named Teamwork, but for various hard to
change reasons we import packages as teamwork (lower case t). To enforce
this we add an import enforcement for our packages:
package duck // import "github.com/teamwork/duck"
This works well, but godoc.org enforces users to use the canonical
GitHub path (Teamwork), but with the import statement the Go compiler
enforces a different path, leading to an error.
Instead of immediately redirecting in the gosrc package, it will now
only store the canonical import path there. This is before the Go source
code is actually scanned, so we don't *actually* know what the real
canonical path should be.
In the doc.newPackage() function it will check for the canonical import
path, taking both the Go import path as well as the reported path from
the gosrc package in to account, and redirect as needed.
This seems to work for all the cases I can think of:
github.com/Teamwork/validate -> github.com/teamwork/validate
github.com/pkg/ERRORS -> github.com/pkg/errors
github.com/Carpetsmoker/sconfig -> arp242.net/sconfig
arp242.net/SCONFIG -> not found (expected)
bitbucket.org/pkg/inflect -> works
bitbucket.org/pkg/INFLECT -> works (should probably redirect too)
github.com/docker/docker/client -> works (#534)
github.com/moby/moby/client -> redirects (on master this actually seems to error out?)
It should also be easy to add a similar check for for some other repo
providers, such as BitBucket, GitLab, etc.
Reviewed-by: Dmitri Shuralyov <firstname.lastname@example.org>
3 files changed