aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bindata.go12
-rw-r--r--config.go12
-rw-r--r--config_test.go24
-rw-r--r--handler.go2
-rw-r--r--templates/package.html2
5 files changed, 42 insertions, 10 deletions
diff --git a/bindata.go b/bindata.go
index 0b3117d..6dae21c 100644
--- a/bindata.go
+++ b/bindata.go
@@ -82,12 +82,12 @@ func templatesIndexHtml() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "templates/index.html", size: 1412, mode: os.FileMode(420), modTime: time.Unix(1583193826, 0)}
+ info := bindataFileInfo{name: "templates/index.html", size: 1412, mode: os.FileMode(420), modTime: time.Unix(1620900995, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
-var _templatesPackageHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\xd1\x3f\x4f\xf3\x30\x10\x06\xf0\xfd\xfd\x14\xf7\x86\xb9\x35\x33\x38\x5d\x0a\x62\xa9\xa0\xaa\x60\x60\x34\xc9\xd3\xd8\x92\xed\x0b\xf6\xa5\x12\x8a\xf2\xdd\x51\x70\xa5\x82\x28\x82\xc9\x7f\xf5\xbb\x47\x77\xfa\xff\xcd\xc3\xfa\xf1\x79\x7b\x4b\x56\x82\x5f\xfd\xd3\x65\x21\x22\xd2\x16\xa6\x2d\xdb\x8f\x63\x80\x18\x8a\x26\xa0\xae\x3a\x5e\xb8\xd0\x73\x92\x8a\x1a\x8e\x82\x28\x75\x35\x8e\xb4\x5c\x9b\xc8\xd1\x35\xc6\x3f\xed\x36\x34\x4d\xd4\x39\x21\x2b\xd2\xe7\x2b\xa5\xe6\xf7\x1d\x7a\xa6\x69\xaa\x7e\x54\x33\x0f\xa9\xc1\x2f\xea\x19\xf1\xdc\x9d\x92\x04\xa8\x60\xb2\x20\x8d\xaa\x75\xe9\x8f\xbf\xd4\xb8\x77\x1e\xd3\xc5\x66\xf4\x2e\xe2\x7b\xd8\x19\x59\xe0\x75\x70\x87\xba\x4a\xd8\x27\x64\xfb\x29\xf0\xe5\x35\x0d\xc9\xd7\x73\x85\x3b\x6e\xb9\x29\x99\x8f\x88\x56\xa7\x9e\xea\x17\x6e\xdf\x4e\xf6\x3d\x8b\x75\xb1\x23\x61\xca\x00\x59\x24\x2c\x69\xeb\x61\x32\x48\x1b\xb2\x09\xfb\xd2\x8d\x2f\x6a\xe0\x03\xc8\x78\x8e\x9d\x56\x66\xb5\x3c\x16\x29\xb2\x56\x65\x96\xef\x01\x00\x00\xff\xff\x69\xc7\x6b\xa3\xe3\x01\x00\x00")
+var _templatesPackageHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x94\xd1\x31\x4f\xf3\x30\x10\x06\xe0\xfd\xfb\x15\xf7\x85\xb9\x35\x33\x38\x1d\x28\x88\xa5\x82\xaa\x82\x81\xd1\x24\x6f\x62\x4b\x8e\x2f\x38\x97\x4a\x28\xf2\x7f\x47\xa9\x2b\x15\x44\x11\x62\xb2\x7d\xb6\x1e\x9f\x5f\xeb\xff\xb7\x8f\xeb\xa7\x97\xed\x1d\x59\xe9\xfc\xea\x9f\xce\x03\x11\x91\xb6\x30\x75\x9e\x1e\x96\x1d\xc4\x50\x30\x1d\xca\xa2\xe5\x85\xeb\x7a\x8e\x52\x50\xc5\x41\x10\xa4\x2c\xa6\x89\x96\x6b\x13\x38\xb8\xca\xf8\xe7\xdd\x86\x52\xa2\xd6\x09\x59\x91\x7e\xb8\x52\x6a\xde\xdf\xa1\x67\x4a\xa9\xf8\x51\x1d\x78\x8c\x15\x7e\x51\xcf\x88\xe7\x6a\x4a\x22\x70\x28\xdc\x44\x13\x2a\x4b\x29\x4d\xaa\x76\xf1\x6f\x87\xd5\xd4\x38\x8f\x74\xb1\x99\xbc\x0b\xf8\xde\xfa\x6c\x2d\xf0\x36\xba\x7d\x59\x44\x34\x11\x83\xfd\xd4\xfe\xe5\x35\x8d\xd1\x97\xb3\x7b\xcf\x35\x57\xf9\x05\x47\x44\xab\x53\xc2\xfa\x95\xeb\xf7\x93\xfd\xc0\x62\x5d\x68\x49\x98\x06\x80\x2c\x22\x96\xb4\xf5\x30\x03\x48\x1b\xb2\x11\x4d\xce\xe6\x8b\xda\xf1\x1e\x64\x3c\x87\x56\x2b\xb3\x5a\x1e\x2f\xc9\xb2\x56\xf9\x67\x3f\x02\x00\x00\xff\xff\x0b\xa0\xa0\x2d\xf1\x01\x00\x00")
func templatesPackageHtmlBytes() ([]byte, error) {
return bindataRead(
@@ -102,7 +102,7 @@ func templatesPackageHtml() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "templates/package.html", size: 483, mode: os.FileMode(420), modTime: time.Unix(1583192015, 0)}
+ info := bindataFileInfo{name: "templates/package.html", size: 497, mode: os.FileMode(420), modTime: time.Unix(1620907647, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
@@ -159,7 +159,7 @@ func AssetNames() []string {
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){
- "templates/index.html": templatesIndexHtml,
+ "templates/index.html": templatesIndexHtml,
"templates/package.html": templatesPackageHtml,
}
@@ -202,9 +202,10 @@ type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
+
var _bintree = &bintree{nil, map[string]*bintree{
"templates": &bintree{nil, map[string]*bintree{
- "index.html": &bintree{templatesIndexHtml, map[string]*bintree{}},
+ "index.html": &bintree{templatesIndexHtml, map[string]*bintree{}},
"package.html": &bintree{templatesPackageHtml, map[string]*bintree{}},
}},
}}
@@ -255,4 +256,3 @@ func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}
-
diff --git a/config.go b/config.go
index c40b2bd..1699e7f 100644
--- a/config.go
+++ b/config.go
@@ -10,6 +10,7 @@ import (
)
const _defaultGodocServer = "pkg.go.dev"
+const _defaultBranch = "master"
// Config represents the structure of the yaml file
type Config struct {
@@ -22,7 +23,8 @@ type Config struct {
// Package details the options available for each repo
type Package struct {
- Repo string `yaml:"repo"`
+ Repo string `yaml:"repo"`
+ Branch string `yaml:"branch"`
}
// ensureAlphabetical checks that the packages are listed alphabetically in the configuration.
@@ -75,5 +77,13 @@ func Parse(path string) (*Config, error) {
c.Godoc.Host = host
}
+ // set default branch
+ for v, p := range c.Packages {
+ if p.Branch == "" {
+ p.Branch = _defaultBranch
+ c.Packages[v] = p
+ }
+ }
+
return &c, err
}
diff --git a/config_test.go b/config_test.go
index bf64085..e87954b 100644
--- a/config_test.go
+++ b/config_test.go
@@ -15,6 +15,7 @@ url: google.golang.org
packages:
grpc:
repo: github.com/grpc/grpc-go
+ branch: main
`)
defer clean()
@@ -28,7 +29,26 @@ packages:
pkg, ok := config.Packages["grpc"]
assert.True(t, ok)
- assert.Equal(t, pkg, Package{Repo: "github.com/grpc/grpc-go"})
+ assert.Equal(t, pkg, Package{Repo: "github.com/grpc/grpc-go", Branch: "main"})
+}
+
+func TestParseDefaultBranch(t *testing.T) {
+ path, clean := TempFile(t, `
+
+url: google.golang.org
+packages:
+ grpc:
+ repo: github.com/grpc/grpc-go
+
+`)
+ defer clean()
+
+ config, err := Parse(path)
+ assert.NoError(t, err)
+
+ pkg, ok := config.Packages["grpc"]
+ assert.True(t, ok)
+ assert.Equal(t, pkg, Package{Repo: "github.com/grpc/grpc-go", Branch: "master"})
}
func TestParseGodocServer(t *testing.T) {
@@ -62,7 +82,7 @@ packages:
pkg, ok := config.Packages["grpc"]
assert.True(t, ok)
- assert.Equal(t, Package{Repo: "github.com/grpc/grpc-go"}, pkg)
+ assert.Equal(t, Package{Repo: "github.com/grpc/grpc-go", Branch: "master"}, pkg)
})
}
}
diff --git a/handler.go b/handler.go
index 2f32132..a29f399 100644
--- a/handler.go
+++ b/handler.go
@@ -55,10 +55,12 @@ func (h packageHandler) Handle(w http.ResponseWriter, r *http.Request, ps httpro
canonicalURL := fmt.Sprintf("%s/%s", h.config.URL, h.pkgName)
data := struct {
Repo string
+ Branch string
CanonicalURL string
GodocURL string
}{
Repo: h.pkg.Repo,
+ Branch: h.pkg.Branch,
CanonicalURL: canonicalURL,
GodocURL: fmt.Sprintf("https://%s/%s%s", h.config.Godoc.Host, canonicalURL, ps.ByName("path")),
}
diff --git a/templates/package.html b/templates/package.html
index 38deaf3..293b392 100644
--- a/templates/package.html
+++ b/templates/package.html
@@ -2,7 +2,7 @@
<html>
<head>
<meta name="go-import" content="{{ .CanonicalURL }} git https://{{ .Repo }}">
- <meta name="go-source" content="{{ .CanonicalURL }} https://{{ .Repo }} https://{{ .Repo }}/tree/master{/dir} https://{{ .Repo }}/tree/master{/dir}/{file}#L{line}">
+ <meta name="go-source" content="{{ .CanonicalURL }} https://{{ .Repo }} https://{{ .Repo }}/tree/{{ .Branch }}{/dir} https://{{ .Repo }}/tree/{{ .Branch }}{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url={{ .GodocURL }}">
</head>
<body>