gopkg

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

gopkg for Caddy v2

This is a port of the gopkg plugin to Caddy v2.

The plugin allows to easily setup vanity gopkg/go module names through a Caddy-powered website.

Usage

gopkg [path] [repo-uri]

gopkg [path] [vcs] [repo-uri]

zikes.me {
  // default vcs is git
  gopkg /multistatus https://github.com/zikes/multistatus
  gopkg /chrisify https://github.com/zikes/chrisify

  // use mercurial
  gopkg /myrepo hg https://bitbucket.org/zikes/myrepo
}

The above would make the repos go get-able via go get zikes.me/chrisify, go get zikes.me/myrepo, and go get zikes.me/multistatus.

If the urls are visited normally the browser will be redirected to the repo uri.

Once implemented, go get can enforce your import paths with import path checking.

Documentation

Overview

Package gopkg implements quick & simple go vanity package import paths.

Vanity go package import paths give a cleaner appearance to go projects by separating the source code location from the import path. It also gives flexibility to developers by allowing them to change a project's source code hosting platform without requiring the project to be renamed. Finally, it allows projects hosted on various platforms to be grouped under a common import path.

Within a Caddyfile, new go packages are added using the gopkg directive:

gopkg <path> [<vcs>] <uri>

The <path> argument corresponds to the path component of the vanity import path, e.g. for "magnax.ca/caddy/gopkg", the path would be "/caddy/gopkg". The <vcs> argument is optional, and defaults to "git". If it is specified, it is used to indicate which version control system is being used to manage the source. The <uri> argument corresponds to the URL/URL of the source code repository. Any format supported by the given VCS and the "go get" tool is can be used, as gopkg does not attempt to validate it.

Index

Constants

View Source
const DefaultTemplate = `` /* 142-byte string literal not displayed */

DefaultTemplate is the default HTML template used as a response.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoPackage added in v1.2.0

type GoPackage struct {
	// Path is the HTTP path component of the vanity import path.
	//
	// Given a vanity import path of `web.site/package/name`, the path would be `/package/name`.
	Path string `json:"path"`

	// Vcs is the version control system used by the package.
	//
	// If empty, the default is `git`.
	// Valid values include `git`, `hg`, `svn`, `bzr`, `cvs`. Basically, any version control system that go knows how to address.
	Vcs string `json:"vcs,omitempty"`

	// URL is the URL of the package's source.
	//
	// This is where the go tool will go to download the source code.
	URL string `json:"url"`

	// Template is the template used when returning a response (instead of redirecting).
	Template *template.Template
}

GoPackage implements vanity go package import paths.

Vanity go package import paths give a cleaner appearance to go projects by separating the source code location from the import path. It also gives flexibility to developers by allowing them to change a project's source code hosting platform without requiring the project to be renamed. Finally, it allows projects hosted on various platforms to be grouped under a common import path.

func (GoPackage) CaddyModule added in v1.2.0

func (m GoPackage) CaddyModule() caddy.ModuleInfo

func (*GoPackage) Provision added in v1.2.0

func (m *GoPackage) Provision(ctx caddy.Context) error

func (GoPackage) ServeHTTP added in v1.2.0

func (m GoPackage) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error

func (*GoPackage) UnmarshalCaddyfile added in v1.2.0

func (m *GoPackage) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler. Syntax:

gopkg <path> [<vcs>] <uri>

Jump to

Keyboard shortcuts

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