goimport

package module
v0.0.0-...-e36ecd4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2013 License: MIT Imports: 6 Imported by: 0

README

goimport

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

Read the docs, and note the github package.

Installation

go get j4k.co/goimport

New to Go? Have a look at how import paths work.

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/",
	}))
}
Output:

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.

Directories

Path Synopsis
Package github finds package paths on GitHub for the goimport package.
Package github finds package paths on GitHub for the goimport package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL