Documentation
¶
Overview ¶
Package goimport provides redirection to godoc.org or to a remote import path for `go get` requests. This allows you to use your domain for import paths while hosting your packages elsewhere. Read more: http://golang.org/cmd/go/#hdr-Remote_import_path_syntax
goimport.Handle(otherHandler, goimport.Packages{
{
VCS: "git",
Path: "somerepo1",
TargetURL: "github.com/someuser/somerepo",
},
})
With the above, goimport.Handle will redirect `go get` requests of example.com/somerepo to github.com/someuser/somerepo. For any paths that do not match a package, requests fall back to otherHandler.
The go tool always passes the `?go-get=1` query in its request. When the query is not found, the HTTP client is given a 302 redirect to godoc.org/{host}/{prefix}/basepath.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is the http.Handler
func Handle ¶
func Handle(root http.Handler, sources ...PackageFinder) *Handler
Handle takes a root http.Handler and returns a wrapper which serves out go-import meta tags for the go tool, or redirects to godoc.org when there is no ?go-get=1 query. For anything that does not match, your root handler is called. If root is nil, we use http.NotFoundHandler.
Example ¶
package main
import (
"j4k.co/goimport"
"j4k.co/goimport/github"
"net/http"
)
func main() {
// root could be your router from gorilla/mux (or your router of
// choice), or a subhandler if you want to use a path prefix like
// /pkg/ or /go/.
root := http.NotFoundHandler()
http.Handle("/", goimport.Handle(root, goimport.Packages{
{
VCS: "git",
Path: "repo1",
TargetURL: "github.com/username/repo1",
},
{
VCS: "bzr",
Path: "repo2",
TargetURL: "launchpad.net/repo2",
},
}, github.Packages{
User: "james4k",
FilterByHomepage: "(http://)?j4k.co/",
}))
}
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP serves our redirect, html meta tag, or the root http.Handler.
func (*Handler) SetPackages ¶
func (h *Handler) SetPackages(src PackageFinder, pkgs []Package)
SetPackages is called by PackageFinders for updating our set of packages.
type Package ¶
type Package struct {
VCS string // git, hg, bzr, or svn
Path string // http path
RootPath string // root import path. optional; defaults to Path
TargetURL string // target import path we forward people to
}
Package represents a package's set of paths to locate its code repository.
type PackageFinder ¶
type PackageFinder interface {
FindPackages(PackageSetter)
}
PackageFinder is used to find new package paths.
type PackageSetter ¶
type PackageSetter interface {
SetPackages(PackageFinder, []Package)
}
PackageSetter is used by PackageFinder to update a set of packages.
type Packages ¶
type Packages []Package
Packages is a slice of Package's that implements PackageFinder
func (Packages) FindPackages ¶
func (p Packages) FindPackages(dest PackageSetter)
FindPackages is called by goimport.Wrap when setting up a list of package paths.