README

go-vanity

Go vanity URLs

Expand ▾ Collapse ▴

Documentation

Overview

Package vanity provides http handler implementations for go vanity URL support.

Index

Constants

View Source
const MetaTemplateLine = `<meta name="go-import" content="{{.Prefix}}{{.Path}} {{.VCS}} {{.URL}}">`

MetaTemplateLine is the html->head->meta line that must exist in vanity page html template.

Variables

This section is empty.

Functions

func Handler

func Handler(args Args) http.HandlerFunc

Handler creates an HTTP handler that handles go vanity URL requests.

func IndexHandler

func IndexHandler(args Args) http.HandlerFunc

IndexHandler creates a handler to render the index page.

Note that by default this is already included in Handler so you don't need to use it directly. It's provided, along with Args.NoIndex, so that you could put the index page on a different path.

Types

type Args

type Args struct {
	Config Config

	// If set to true, do not render and handle the index page.
	NoIndex bool
}

Args defines the args used by Handler function.

type Config

type Config struct {
	// The vanity import prefix shared by all paths, without URL schema and
	// trailing "/".
	//
	// Example:
	//
	//     go.yhsif.com
	//
	// Or:
	//
	//     yhsif.com/go
	Prefix string `yaml:"prefix" json:"prefix"`

	// The mappings of the repositories.
	Mappings []Mapping `yaml:"mappings" json:"mappings"`
}

Config defines the configuration used by the http handler.

type Mapping

type Mapping struct {
	// The path of the vanity URL, with leading "/"/
	//
	// Example:
	//
	//     /vanity
	Path string `yaml:"path" json:"path"`

	// The full URL of the actual repository.
	//
	// Example:
	//
	//     https://github.com/fishy/go-vanity
	URL string `yaml:"url" json:"url"`

	// The VCS of the repository. Default to DefaultVCS ("git").
	VCS VCS `yaml:"vcs" json:"vcs"`

	// A brief description to be shown on the index page.
	Description string `yaml:"description" json:"description"`

	// If set to true, do not show this mapping in index page.
	HideInIndex bool `yaml:"unlist" json:"unlist"`
}

Mapping defines a mapping from a vanity path to an actual repository.

type PageTmplData

type PageTmplData struct {
	// From Config.Prefix.
	Prefix string

	// From Config.Mappings
	Path string
	URL  string
	VCS  VCS

	// The path from the request,
	// could be different from Path but always have Path as prefix.
	Reqpath string
}

PageTmplData is the data used to execute PageTmpl.

type Templater

type Templater interface {
	Execute(io.Writer, interface{}) error
}

Templater is the minimal interface shared between go's text and html templates.

var IndexTmpl Templater = template.Must(template.New("index").Parse("" /* 595 byte string literal not displayed */))

IndexTmpl is the html template used to render the index page.

It's exported so users of this package could replace it to a different one if they so desire.

The data used to execute the template is Config.

var PageTmpl Templater = template.Must(template.New("vanity").Parse(`<!DOCTYPE html>
<html>
<head>
<title>Vanity page for {{.Prefix}}{{.Reqpath}}</title>
` + MetaTemplateLine + "" /* 286 byte string literal not displayed */,
))

PageTmpl is the html template used to render the vanity pages.

It's exported so users of this package could replace it to a different one if they so desire. But when replacing it, MetaTemplateLine (or equivalent) must exists in the template, or the vanity page might be invalid.

The data used to execute the template is defined in PageTmplData.

type VCS

type VCS string

VCS defines the vcs ("git", "mod", "hg", etc.) used in Mapping.

It treats zero value (empty string) as DefaultVCS, and behave the same as strings otherwise.

const (
	DefaultVCS VCS = "git"
)

The default VCS to be used.

func (VCS) MarshalText

func (v VCS) MarshalText() (text []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (VCS) String

func (v VCS) String() string

func (*VCS) UnmarshalText

func (v *VCS) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Directories

Path Synopsis
MODULE appengine