diff --git a/Makefile b/Makefile
index 1555272..1592160 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,24 @@
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
-vanityserver:
- $(GO) build $(GOFLAGS) ./cmd/$@
+VERSION = `git describe --abbrev=0 --tags 2>/dev/null || echo "$VERSION"`
+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 -m0755 vanityserver $(PREFIX)/bin/vanityserver
+ install -m0755 toyohime-server $(PREFIX)/bin/toyohime-server
+test:
+ ${GO} test .
uninstall:
- rm -f $(PREFIX)/bin/vanityserver
+ rm -f $(PREFIX)/bin/toyohime-server
diff --git a/cmd/vanityserver/README.md b/cmd/toyohime-server/README.md
similarity index 100%
rename from cmd/vanityserver/README.md
rename to cmd/toyohime-server/README.md
diff --git a/cmd/vanityserver/dynamic_handler.go b/cmd/toyohime-server/dynamic_handler.go
similarity index 100%
rename from cmd/vanityserver/dynamic_handler.go
rename to cmd/toyohime-server/dynamic_handler.go
diff --git a/cmd/vanityserver/main.go b/cmd/toyohime-server/main.go
similarity index 60%
rename from cmd/vanityserver/main.go
rename to cmd/toyohime-server/main.go
index 9553a33..5c45928 100644
--- a/cmd/vanityserver/main.go
+++ b/cmd/toyohime-server/main.go
@@ -38,7 +38,7 @@ import (
"strings"
"time"
- "git.chaotic.ninja/koizumi.aoi/vanity"
+ "marisa.chaotic.ninja/toyohime"
)
var (
@@ -66,9 +66,9 @@ func serveRepo(mux *http.ServeMux, root string, u *url.URL) {
importPath := host + "/" + root
var h http.Handler
if vcsHost == "github.com" {
- h = vanity.GitHubHandler(importPath, user, repo, vcsScheme)
+ h = toyohime.GitHubHandler(importPath, user, repo, vcsScheme)
} 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)
@@ -107,18 +107,77 @@ func addRepoHandlers(mux *http.ServeMux, r io.Reader) error {
}
var b bytes.Buffer
- err := template.Must(template.New("").Parse(`
-
+ err := template.Must(template.New("").Parse(`
+
+
+
+Import paths hosted at {{ .Host }}
+
+
+
{{ $host := .Host }}
-{{ html $host }}
+
+
でホストされているインポート パス {{ html $host }}
+
+
+
+
`)).Execute(&b, struct {
IndexMap map[string]string
Host string
@@ -218,5 +277,6 @@ func main() {
srv := buildServer(h)
+ log.Printf("starting toyohime-server %v on port %v\n", toyohime.FullVersion(), *listenPort)
log.Println(srv.ListenAndServe())
}
diff --git a/go.mod b/go.mod
index b89bf52..e2712e7 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module git.chaotic.ninja/koizumi.aoi/vanity
+module marisa.chaotic.ninja/toyohime
go 1.14
diff --git a/vanity.go b/toyohime.go
similarity index 97%
rename from vanity.go
rename to toyohime.go
index ead31f5..951c79a 100644
--- a/vanity.go
+++ b/toyohime.go
@@ -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.
*/
-package vanity // import "go.jonnrb.io/vanity"
+package toyohime // import "go.jonnrb.io/vanity" <- original one for reference
import (
"fmt"
diff --git a/vanity_test.go b/toyohime_test.go
similarity index 93%
rename from vanity_test.go
rename to toyohime_test.go
index ddd5657..bf6598f 100644
--- a/vanity_test.go
+++ b/toyohime_test.go
@@ -1,4 +1,4 @@
-package vanity
+package toyohime
import (
"io/ioutil"
@@ -52,9 +52,9 @@ func TestBrowserGoDoc(t *testing.T) {
path string
result string
}{
- {"/pkg", "https://godoc.org/go.jonnrb.io/pkg"},
- {"/pkg/", "https://godoc.org/go.jonnrb.io/pkg"},
- {"/pkg/sub/foo", "https://godoc.org/go.jonnrb.io/pkg/sub/foo"},
+ {"/pkg", "https://godocs.io/go.jonnrb.io/pkg"},
+ {"/pkg/", "https://godocs.io/go.jonnrb.io/pkg"},
+ {"/pkg/sub/foo", "https://godocs.io/go.jonnrb.io/pkg/sub/foo"},
}
for _, test := range tests {
res := httptest.NewRecorder()
diff --git a/version.go b/version.go
new file mode 100644
index 0000000..81e847c
--- /dev/null
+++ b/version.go
@@ -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 ..
+ // 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()
+}