vanity

package
v0.0.0-...-e5308a5 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2013 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package vanity provides an http.Handler to serve links for vanity packages.

Index

Constants

This section is empty.

Variables

View Source
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

func (s *Server) LoadProjects(glob string) error

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

func (s *Server) LoadTemplates(glob string) error

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.

func (*Server) Stale

func (s *Server) Stale() bool

Stale returns true if any of the files matching the ProjectGlob or TemplateGlob have been modified since they were last Loaded. If an error is encountered, it is considered stale. Errors and stale files are logged.

Jump to

Keyboard shortcuts

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