vain/vain.go

55 lines
1.1 KiB
Go
Raw Normal View History

2016-02-15 01:10:14 -08:00
// Package vain implements a vanity service for use by the the go tool.
//
// The executable, cmd/ysvd, is located in the respective subdirectory.
2016-02-11 11:57:16 -08:00
package vain
2016-02-07 23:54:55 -08:00
import "fmt"
type vcs int
const (
2016-02-15 01:10:14 -08:00
// Git is the default Vcs.
2016-02-07 23:54:55 -08:00
Git vcs = iota
2016-02-15 01:10:14 -08:00
// Hg is mercurial
2016-02-07 23:54:55 -08:00
Hg
)
var vcss = [...]string{
"git",
"mercurial",
}
var labelToVcs = map[string]vcs{
"git": Git,
"mercurial": Hg,
"hg": Hg,
}
// String returns the name of the vcs ("git", "mercurial", ...).
func (v vcs) String() string { return vcss[v] }
2016-02-15 01:10:14 -08:00
// Package stores the three pieces of information needed to create the meta
// tag. Two of these (Vcs and Repo) are stored explicitly, and the third is
// determined implicitly by the path POSTed to. For more information refer to
// the documentation for the go tool:
//
// https://golang.org/cmd/go/#hdr-Remote_import_paths
2016-02-08 00:14:30 -08:00
type Package struct {
2016-02-15 01:10:14 -08:00
//Vcs (version control system) supported: "git", "mercurial"
Vcs vcs `json:"vcs"`
// Repo: the remote repository url
2016-02-07 23:54:55 -08:00
Repo string `json:"repo"`
2016-02-15 01:10:14 -08:00
path string
2016-02-07 23:54:55 -08:00
}
2016-02-08 00:14:30 -08:00
func (p Package) String() string {
2016-02-07 23:54:55 -08:00
return fmt.Sprintf(
"<meta name=\"go-import\" content=\"%s %s %s\">",
2016-02-15 01:10:14 -08:00
p.path,
2016-02-07 23:54:55 -08:00
p.Vcs,
p.Repo,
)
}