-
Notifications
You must be signed in to change notification settings - Fork 124
Vanity Import Paths
This document contains information about using vanity import paths for Go packages.
With vanity import paths it will be possible to retrieve Go packages using custom domain. For example:
# instead of this
go get github.com/ligato/vpp-agent
# users can use
go get go.ligato.io/vpp-agent
To make this work, the webserver running on ligato.io has to serve proper meta tags when the go command client is downloading.
First we setup redirect for /vpp-agent
path in the file _redirects
:
/vpp-agent* go-get=1 /golang/vpp-agent.html 200
Then we define the page that will be served to clients:
<html><head>
<meta name="go-import" content="ligato.io/vpp-agent git https://github.com/ligato/vpp-agent">
<meta name="go-source" content="ligato.io/vpp-agent https://github.com/ligato/vpp-agent https://github.com/ligato/vpp-agent/tree/master{/dir} https://github.com/ligato/vpp-agent/blob/master{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url=https://godoc.org/ligato.io/vpp-agent" />
</head></html>
go.mod
files contains it already)
With canonical import paths we can restrict download of the go packages only to the vanity import path. This will make go command fail when trying to download the package directly from GitHub.
$ go get -v github.com/ligato/infra
github.com/ligato/infra (download)
package github.com/ligato/infra: code in directory /go/src/github.com/ligato/infra expects import "ligato.io/pkg/infra"
To define the canonical import path we add following comment to package declaration:
package main // import "ligato.io/vpp-agent/cmd/vpp-agent"