Documentation ¶
Overview ¶
Package vanity provides an http.Handler to serve links for vanity packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var GoDoc = "http://godoc.org/"
GoDoc is the prefix applied to import paths to redirect to a documentation aggregator.
Functions ¶
This section is empty.
Types ¶
type Project ¶
type Project struct { // Display Name string // name of the project Desc string // short textual project description Links map[string]string // Extra links Hidden bool // not shown to humans, but visible to the go tool // Meta Imports Import string // exact import path (e.g. "kylelemons.net/go/gofr") VCS string // version control system (e.g. "git", "hg", "svn", "bzr") Repo string // repository checkout URI (e.g. "git://kylelemons.net/go/gofr.git") Source string // Source template for "go-source" meta tag }
A Project is the main element used to render the project display page.
type Server ¶
type Server struct { // Rendering Analytics string // Google Analytics Property ID (e.g. UA-12345678-1) Templates *template.Template // templates from which "main" will be rendered Projects map[string]Project // Projects[subpath] = project Extra map[string]interface{} // extra data available in the templates // Serving Reload bool // true if templates and projects should be reloaded when stale TemplateGlob string // if nonzero and Reload is true, template glob to load ProjectGlob string // if nonzero and Reload is true, project file to load // contains filtered or unexported fields }
A Server serves vanity package pages.
The template has the following available:
{{.Projects}} - The Projects map from the Server {{.RedirectURL}} - The URL to which the user is being redirected (if any)
The following are also available for analytics:
{{.gaID}} - Analytics property ID (from the Server) {{.gaAction}} - The action being performed (e.g. "List" or "Documentation") {{.gaArg}} - The action argument, if any (package name for Documentation)
Any key/val pairs in Extra will be available to the template as well, and will override any vanity-defined keys (to maintain forward compatibiity).
func (*Server) LoadProjects ¶
LoadProjects loads json map[string]Project files into the server's Projects field from the given glob and, if successful, stores the glob in the ProjectGlob field for use with Reload.
func (*Server) LoadTemplates ¶
LoadTemplates loads templates into the server's Templates field from the given glob and, if successful, stores the glob in the TemplateGlob field for use with Reload.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves on a directory (prefixes should be stripped) and executes the Server's templates based on the path. The template is always executed, but if the subpath of this handler matches the key of a project in the Projects map, a Refresh header is sent to the browser to redirect to the documentation for the matched package after 3 seconds. See the Server documentation for the fields which are available to the templates.