This commit is contained in:
Stephen McQuay 2016-02-07 23:54:55 -08:00
commit 8ef813e55d
6 changed files with 129 additions and 0 deletions

4
cmd/ysvd/main.go Normal file
View File

@ -0,0 +1,4 @@
package main
func main() {
}

2
doc.go Normal file
View File

@ -0,0 +1,2 @@
// package ysv implements a vanity service for use by the the go tool
package ysv

27
licence.txt Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 2016, stephen mcquay
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of ysv nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

11
readme.md Normal file
View File

@ -0,0 +1,11 @@
# ysv
`ysvd` is a vanity url server for use by the `go` tool.
## installation
$ go get mcquay.me/ysv/cmd/ysvd
## running server
$ ysvd

48
ysv.go Normal file
View File

@ -0,0 +1,48 @@
/*
From the documentation for the go tool, it searches for the following header
when searching for packages:
<meta name="go-import" content="import-prefix vcs repo-root">
ysv stands for You're so Vain, the song by Carly Simon.
*/
package ysv
import "fmt"
type vcs int
const (
Git vcs = iota
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] }
type pkg struct {
Vcs vcs `json":vcs"`
Path string `json:"path"`
Repo string `json:"repo"`
}
func (p pkg) String() string {
return fmt.Sprintf(
"<meta name=\"go-import\" content=\"%s %s %s\">",
p.Path,
p.Vcs,
p.Repo,
)
}

37
ysv_test.go Normal file
View File

@ -0,0 +1,37 @@
package ysv
import (
"fmt"
"testing"
)
func TestString(t *testing.T) {
p := pkg{
Path: "mcquay.me/bps",
Repo: "https://s.mcquay.me/sm/bps",
}
got := fmt.Sprintf("%s", p)
want := `<meta name="go-import" content="mcquay.me/bps git https://s.mcquay.me/sm/bps">`
if got != want {
t.Errorf(
"incorrect converstion to meta; got %s, want %s",
got,
want,
)
}
}
func TestVcsStrings(t *testing.T) {
tests := []struct {
got string
want string
}{
{fmt.Sprintf("%+v", Git), "git"},
{fmt.Sprintf("%+v", Hg), "mercurial"},
}
for _, test := range tests {
if test.got != test.want {
t.Errorf("incorrect conversion of ysv.Vcs -> string; got %q, want %q", test.got, test.want)
}
}
}