aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go1
-rw-r--r--config_test.go20
-rw-r--r--handler.go6
-rw-r--r--handler_test.go20
-rw-r--r--templates/index.html3
5 files changed, 49 insertions, 1 deletions
diff --git a/config.go b/config.go
index 1699e7f..e322da3 100644
--- a/config.go
+++ b/config.go
@@ -25,6 +25,7 @@ type Config struct {
type Package struct {
Repo string `yaml:"repo"`
Branch string `yaml:"branch"`
+ URL string `yaml:"url"`
}
// ensureAlphabetical checks that the packages are listed alphabetically in the configuration.
diff --git a/config_test.go b/config_test.go
index e87954b..eb6c463 100644
--- a/config_test.go
+++ b/config_test.go
@@ -51,6 +51,26 @@ packages:
assert.Equal(t, pkg, Package{Repo: "github.com/grpc/grpc-go", Branch: "master"})
}
+func TestParsePackageLevelURL(t *testing.T) {
+ path, clean := TempFile(t, `
+
+url: google.golang.org
+packages:
+ grpc:
+ repo: github.com/grpc/grpc-go
+ url: go.uber.org
+
+`)
+ defer clean()
+
+ config, err := Parse(path)
+ assert.NoError(t, err)
+
+ pkg, ok := config.Packages["grpc"]
+ assert.True(t, ok)
+ assert.Equal(t, pkg.URL, "go.uber.org")
+}
+
func TestParseGodocServer(t *testing.T) {
tests := []struct {
give string
diff --git a/handler.go b/handler.go
index b10b8f5..0490a83 100644
--- a/handler.go
+++ b/handler.go
@@ -53,7 +53,11 @@ type packageHandler struct {
}
func (h packageHandler) Handle(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
- canonicalURL := fmt.Sprintf("%s/%s", h.config.URL, h.pkgName)
+ baseURL := h.config.URL
+ if h.pkg.URL != "" {
+ baseURL = h.pkg.URL
+ }
+ canonicalURL := fmt.Sprintf("%s/%s", baseURL, h.pkgName)
data := struct {
Repo string
Branch string
diff --git a/handler_test.go b/handler_test.go
index 978f62d..96a10dd 100644
--- a/handler_test.go
+++ b/handler_test.go
@@ -14,6 +14,9 @@ packages:
repo: github.com/thriftrw/thriftrw-go
yarpc:
repo: github.com/yarpc/yarpc-go
+ zap:
+ url: go.uberalt.org
+ repo: github.com/uber-go/zap
`
@@ -98,3 +101,20 @@ func TestDeepImports(t *testing.T) {
</html>
`)
}
+
+func TestPackageLevelURL(t *testing.T) {
+ rr := CallAndRecord(t, config, "/zap")
+ AssertResponse(t, rr, 200, `
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta name="go-import" content="go.uberalt.org/zap git https://github.com/uber-go/zap">
+ <meta name="go-source" content="go.uberalt.org/zap https://github.com/uber-go/zap https://github.com/uber-go/zap/tree/master{/dir} https://github.com/uber-go/zap/tree/master{/dir}/{file}#L{line}">
+ <meta http-equiv="refresh" content="0; url=https://pkg.go.dev/go.uberalt.org/zap">
+ </head>
+ <body>
+ Nothing to see here. Please <a href="https://pkg.go.dev/go.uberalt.org/zap">move along</a>.
+ </body>
+</html>
+`)
+}
diff --git a/templates/index.html b/templates/index.html
index 50b6004..2599bf0 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -17,6 +17,9 @@
<tbody>
{{ range $key, $value := .Packages }}
{{ $importPath := printf "%v/%v" $.URL $key }}
+ {{ if ne $value.URL "" }}
+ {{ $importPath = printf "%v/%v" $value.URL $key }}
+ {{ end }}
<tr>
<td>{{ $importPath }}</td>
<td>