Rename from vanity to toyohime

Signed-off-by: Aoi K <koizumi.aoi@chaotic.ninja>

git-svn-id: file:///srv/svn/repo/toyohime/trunk@109 922d331f-388e-da47-97a9-ad700dc0b8b9
This commit is contained in:
koizumi.aoi 2023-03-29 04:44:45 +00:00
parent 5c95c8fdd1
commit f4f3bcf625
8 changed files with 145 additions and 21 deletions

View File

@ -1,10 +1,24 @@
GO ?= go GO ?= go
GOFLAGS ?= -v GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=$(VERSION) -X `go list`.Commit=$(COMMIT) -X `go list`.Build=$(BUILD)" -tags "static_build"
PREFIX ?= /usr/local PREFIX ?= /usr/local
vanityserver: VERSION = `git describe --abbrev=0 --tags 2>/dev/null || echo "$VERSION"`
$(GO) build $(GOFLAGS) ./cmd/$@ COMMIT = `git rev-parse --short HEAD || echo "$COMMIT"`
BRANCH = `git rev-parse --abbrev-ref HEAD`
BUILD = `git show -s --pretty=format:%cI`
GOARCH ?= amd64
GOOS ?= linux
all: toyohime-server
toyohime-server:
${GO} build ${GOFLAGS} ./cmd/toyohime-server
clean:
rm toyohime-server
install: install:
install -m0755 vanityserver $(PREFIX)/bin/vanityserver install -m0755 toyohime-server $(PREFIX)/bin/toyohime-server
test:
${GO} test .
uninstall: uninstall:
rm -f $(PREFIX)/bin/vanityserver rm -f $(PREFIX)/bin/toyohime-server

View File

@ -38,7 +38,7 @@ import (
"strings" "strings"
"time" "time"
"git.chaotic.ninja/koizumi.aoi/vanity" "marisa.chaotic.ninja/toyohime"
) )
var ( var (
@ -66,9 +66,9 @@ func serveRepo(mux *http.ServeMux, root string, u *url.URL) {
importPath := host + "/" + root importPath := host + "/" + root
var h http.Handler var h http.Handler
if vcsHost == "github.com" { if vcsHost == "github.com" {
h = vanity.GitHubHandler(importPath, user, repo, vcsScheme) h = toyohime.GitHubHandler(importPath, user, repo, vcsScheme)
} else { } else {
h = vanity.GogsHandler(importPath, vcsHost, user, repo, vcsScheme) h = toyohime.GogsHandler(importPath, vcsHost, user, repo, vcsScheme)
} }
mux.Handle("/"+root, h) mux.Handle("/"+root, h)
mux.Handle("/"+root+"/", h) mux.Handle("/"+root+"/", h)
@ -107,18 +107,77 @@ func addRepoHandlers(mux *http.ServeMux, r io.Reader) error {
} }
var b bytes.Buffer var b bytes.Buffer
err := template.Must(template.New("").Parse(`<!DOCTYPE html> err := template.Must(template.New("").Parse(`
<table> <!DOCTYPE html>
<html>
<head>
<title>Import paths hosted at {{ .Host }}</title>
<style type="text/css">
body,td{font-size:11pt; color:#4d4d4d; font-family:ms pgothic, ms gothic, osaka; background-color:#f8dfdf}
a:link{color:#cc9999; text-decoration:none}
a:visited{color:#cc9999; text-decoration:none}
a:active{color:#cc9999; text-decoration:none; position:relative; top:3px; left:3px}
a:hover{color:#cc9999; text-decoration:none; position:relative; top:3px; left:3px}
.yohaku{margin-top:30px}
.dia{line-height:130%}
.star1{font-size:22px; color:#cc9999}
.position1{position:relative; top:7px}
.line{border-top:2px dotted #cc9999}
.waku{border:1px solid #cc9999}
.bg{background-color:#ffffff}
</style>
</head>
<body>
{{ $host := .Host }} {{ $host := .Host }}
<h1>{{ html $host }}</h1> <div align="center">
<p>でホストされているインポート パス {{ html $host }}</p>
</div>
<div align="center">
<table width="470" class="bg waku yohaku" cellspacing="0" style="margin-bottom: 20px">
{{ range $root, $repo := .IndexMap }} {{ range $root, $repo := .IndexMap }}
<tr> <tr><td class="bg" style="padding-top: 5px; padding-bottom: 5px">
<td><a href="https://{{ html $host }}/{{ html $root }}">{{ html $root }}</a></td> <div class="star1" align="center">
<td><a href="{{ html $repo }}">{{ html $repo }}</a></td> <span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
<span style="position:relative; top:5px">*</span>
<span style="position:relative; top:-5px">*</span>
</div>
</td></tr>
<tr><td class="bg line dia" style="padding: 15px 10px 10px 10px">
<center>
<h2>{{ html $root }}</h2>
<a href="https://{{ html $host }}/{{ html $root }}">Package</a> <br/>
<a href="{{ html $repo }}">Repository</a></li>
{{ else }} {{ else }}
Nothing here. Nothing here.
{{ end }} {{ end }}
</center>
</table> </table>
<p>から明らかに盗まれた <a href="http://azukifont.com">azukifont.com</a></p>
</div>
</body>
</html>
`)).Execute(&b, struct { `)).Execute(&b, struct {
IndexMap map[string]string IndexMap map[string]string
Host string Host string
@ -218,5 +277,6 @@ func main() {
srv := buildServer(h) srv := buildServer(h)
log.Printf("starting toyohime-server %v on port %v\n", toyohime.FullVersion(), *listenPort)
log.Println(srv.ListenAndServe()) log.Println(srv.ListenAndServe())
} }

2
go.mod
View File

@ -1,4 +1,4 @@
module git.chaotic.ninja/koizumi.aoi/vanity module marisa.chaotic.ninja/toyohime
go 1.14 go 1.14

View File

@ -1,8 +1,8 @@
/* /*
Package vanity implements custom import paths (Go vanity URLs) as an HTTP Package toyohime implements custom import paths (Go vanity URLs) as an HTTP
handler that can be installed at the vanity URL. handler that can be installed at the vanity URL.
*/ */
package vanity // import "go.jonnrb.io/vanity" package toyohime // import "go.jonnrb.io/vanity" <- original one for reference
import ( import (
"fmt" "fmt"

View File

@ -1,4 +1,4 @@
package vanity package toyohime
import ( import (
"io/ioutil" "io/ioutil"
@ -52,9 +52,9 @@ func TestBrowserGoDoc(t *testing.T) {
path string path string
result string result string
}{ }{
{"/pkg", "https://godoc.org/go.jonnrb.io/pkg"}, {"/pkg", "https://godocs.io/go.jonnrb.io/pkg"},
{"/pkg/", "https://godoc.org/go.jonnrb.io/pkg"}, {"/pkg/", "https://godocs.io/go.jonnrb.io/pkg"},
{"/pkg/sub/foo", "https://godoc.org/go.jonnrb.io/pkg/sub/foo"}, {"/pkg/sub/foo", "https://godocs.io/go.jonnrb.io/pkg/sub/foo"},
} }
for _, test := range tests { for _, test := range tests {
res := httptest.NewRecorder() res := httptest.NewRecorder()

50
version.go Normal file
View File

@ -0,0 +1,50 @@
package toyohime
import (
"fmt"
"runtime/debug"
"strings"
)
const (
defaultVersion = "0.0.0"
defaultCommit = "HEAD"
defaultBuild = "0000-01-01:00:00+00:00"
)
var (
// Version is the tagged release version in the form <major>.<minor>.<patch>
// following semantic versioning and is overwritten by the build system.
Version = defaultVersion
// Commit is the commit sha of the build (normally from Git) and is overwritten
// by the build system.
Commit = defaultCommit
// Build is the date and time of the build as an RFC3339 formatted string
// and is overwritten by the build system.
Build = defaultBuild
)
// FullVersion display the full version and build
func FullVersion() string {
var sb strings.Builder
isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
if !isDefault {
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
}
if info, ok := debug.ReadBuildInfo(); ok {
if isDefault {
sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
}
sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
if info.Main.Sum != "" {
sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
}
}
return sb.String()
}