aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--bindata.go4
-rw-r--r--config.go18
-rw-r--r--config_test.go39
-rw-r--r--handler.go2
-rw-r--r--templates/index.html4
6 files changed, 66 insertions, 6 deletions
diff --git a/README.md b/README.md
index 51527ed..3046a78 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,11 @@ A tiny HTTP server for supporting custom Golang import paths
Create a YAML file with the following structure:
```yaml
+# This optional section configures godoc documentation linking.
+godoc:
+ # Instance of godoc.org used for documentation links. Defaults to godoc.org.
+ host: godoc.org
+
url: google.golang.org
packages:
grpc:
diff --git a/bindata.go b/bindata.go
index a2b1492..dbcd8b0 100644
--- a/bindata.go
+++ b/bindata.go
@@ -67,7 +67,7 @@ func (fi bindataFileInfo) Sys() interface{} {
return nil
}
-var _templatesIndexHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xac\x54\x3f\x6f\xdb\x3e\x10\xdd\x7f\x9f\xe2\x7e\x84\xb3\x35\xbc\xa2\xe8\x14\xd0\xee\x50\x17\x5d\x0a\xd4\x48\xdb\xa1\x23\x4d\x9e\x25\xc6\x14\x69\x90\x27\xa5\x46\xa0\xef\x5e\x58\x72\xe2\x44\xae\xe4\x00\xad\x16\x89\xba\xf7\xde\xfd\xe5\xa9\xff\x97\x5f\x3f\x7e\xff\xb9\xfa\x04\x25\x57\x7e\xf1\x9f\xea\x5f\x00\x00\xaa\x24\x6d\xfb\xcf\xee\xe8\x5d\xd8\x42\x22\x3f\x17\x99\xf7\x9e\x72\x49\xc4\x02\xca\x44\x9b\xb9\x28\x99\x77\xf9\x06\xd1\xd8\x70\x97\xa5\xf1\xb1\xb6\x1b\xaf\x13\x49\x13\x2b\xd4\x77\xfa\x17\x7a\xb7\xce\x98\xb7\xe4\x89\x63\xc0\x77\xf2\xad\x7c\xff\x74\x94\x95\x0b\xd2\xe4\x2c\x00\x8f\xae\xf1\xe4\x5b\xad\xa3\xdd\x3f\x0b\xc3\xba\x06\x8c\xd7\x39\xcf\x85\x89\x81\xb5\x0b\x94\xc4\xc9\x3e\xc4\xa4\x78\x3f\xb0\x76\x08\xd6\x6b\x4f\x8f\x98\xfa\x7a\x53\x7b\x7f\x7d\xef\x2c\x97\x7f\x00\xf7\x84\x97\xd5\x38\xb7\xa7\x71\xe3\x51\x60\xb1\xd2\x66\xab\x0b\x52\xc8\xe5\x65\xf0\xb7\x58\x27\xf3\x4a\xec\x32\x9a\xba\xa2\xc0\x9a\x5d\x0c\xd3\x14\x85\x63\x91\x1e\x78\xa3\x39\x2a\x7e\xd9\x86\xe1\xf3\xf0\x00\x49\x87\x82\x60\xb6\xa5\xfd\x1b\x98\x35\xda\xd7\x04\x37\x73\x90\xc7\xa4\x33\xb4\xed\x14\x7b\xe6\xaa\x5d\x4c\xbc\xd2\x5c\x1e\x68\xbb\xe4\x02\x6f\x40\x5c\x35\x78\xd5\x08\x98\xc9\x1f\xb7\x5f\x3a\xed\x29\x99\x57\x34\xc1\x2e\x06\xbe\xda\x56\x21\x4f\x34\xf6\x91\x36\x09\xe8\x40\xfa\x78\x17\x10\x0f\x2e\xba\x02\xc8\x5b\xda\x45\x68\x5b\xb1\x38\xfb\xa5\x50\x5f\x70\xfa\xcf\xc3\x2a\xa2\x8d\x46\xc6\x54\xe0\x59\x0d\x46\xa6\xfe\x4c\xcc\x55\x05\xe4\x64\x2e\xa8\x7d\xc8\xac\xb9\xce\x32\x37\x85\x00\xed\x79\x2e\x3e\xc7\x65\x34\x4f\xd7\x7b\x3a\xed\xbf\xaa\xcb\xf8\x78\x43\x3f\x67\x14\xec\xd8\x08\x29\x1c\x19\x72\x85\xdd\xba\x18\x2c\x19\xb4\xae\x79\xb6\x97\x4e\x47\x85\xbd\x8c\xc2\x7e\x99\xfe\x0e\x00\x00\xff\xff\xb1\x54\x5d\xd8\x64\x05\x00\x00")
+var _templatesIndexHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x54\xc1\x6e\xdb\x30\x0c\xbd\xef\x2b\x38\x21\xbd\xad\xe2\x30\xec\x54\x28\xd9\x61\x19\xba\xc3\x80\x05\xdd\x76\xd8\x51\x91\x98\x58\x8d\x2c\x05\x12\xed\x2e\x28\xfc\xef\x43\xec\xb4\x69\x9d\xd9\x0d\x30\xd4\x17\x9b\xe6\x7b\x8f\x14\x49\x51\xbd\x9d\x7f\xff\xfc\xf3\xf7\xe2\x0b\x14\x5c\xfa\xd9\x1b\xd5\xbd\x00\x00\x54\x41\xda\x76\x9f\xad\xe9\x5d\xd8\x40\x22\x3f\x15\x99\x77\x9e\x72\x41\xc4\x02\x8a\x44\xab\xa9\x28\x98\xb7\xf9\x0a\xd1\xd8\x70\x9b\xa5\xf1\xb1\xb2\x2b\xaf\x13\x49\x13\x4b\xd4\xb7\xfa\x0f\x7a\xb7\xcc\x98\x37\xe4\x89\x63\xc0\x0f\xf2\xbd\xfc\xf8\x68\xca\xd2\x05\x69\x72\x16\x80\x87\xd0\x78\x8c\xad\x96\xd1\xee\x9e\xa4\x61\x5d\x0d\xc6\xeb\x9c\xa7\xc2\xc4\xc0\xda\x05\x4a\xe2\xe8\xef\x63\x52\xbc\xeb\x79\x5b\x04\xeb\xa5\xa7\x07\x4c\x75\xb9\xaa\xbc\xbf\xbc\x73\x96\x8b\x7f\x80\x3b\xc2\xf3\x6a\x9c\xfa\xd3\xb0\xf3\x20\x30\x5b\x68\xb3\xd1\x6b\x52\xc8\xc5\xcb\xe0\x1f\xb1\x4a\xe6\x4c\xec\x3c\x9a\xaa\xa4\xc0\x9a\x5d\x0c\xe3\x14\x85\x43\x99\xee\x79\x83\x67\x54\xfc\xbc\x0d\xfd\xe7\xfe\x1e\x92\x0e\x6b\x82\xc9\x86\x76\xef\x60\x52\x6b\x5f\x11\x5c\x4d\x41\x1e\x0e\x9d\xa1\x69\xc6\xd8\x13\x57\x6e\x63\xe2\x85\xe6\x62\x4f\xdb\x26\x17\x78\x05\xe2\xa2\xc6\x8b\x5a\xc0\x44\xfe\xba\xf9\xd6\x6a\x8f\xc9\x9c\xd1\x04\x3b\xeb\xc5\x6a\x1a\x85\x3c\xd2\xd8\x07\xda\x28\xa0\x05\xe9\xc3\x5d\x40\xdc\x87\x68\x0b\x20\x6f\x68\x1b\xa1\x69\xc4\xec\xe4\x97\x42\xfd\x42\xd0\x57\x49\x4b\x5e\x47\x1b\x8d\xfc\x1a\x33\x43\xd3\xe0\x49\x31\x06\xc6\xff\x44\xd5\x95\x6b\xc8\xc9\x9c\x2b\xfb\x29\xb3\xe6\x2a\xcb\x5c\xaf\x05\x68\xcf\x53\x71\x1d\xe7\xd1\x3c\x5e\xf8\xf1\x42\xfc\x57\xa5\x86\x07\x1e\xba\xc9\xa3\x60\x87\x86\x4a\xe1\xc0\xd8\x2b\x6c\x17\x48\x6f\xed\xa0\x75\xf5\x93\x4d\x75\x34\x15\x76\x32\x0a\xbb\xf5\xfa\x37\x00\x00\xff\xff\x5e\x31\xf2\xd0\x76\x05\x00\x00")
func templatesIndexHtmlBytes() ([]byte, error) {
return bindataRead(
@@ -82,7 +82,7 @@ func templatesIndexHtml() (*asset, error) {
return nil, err
}
- info := bindataFileInfo{name: "templates/index.html", size: 1380, mode: os.FileMode(420), modTime: time.Unix(1546544917, 0)}
+ info := bindataFileInfo{name: "templates/index.html", size: 1398, mode: os.FileMode(420), modTime: time.Unix(1551814013, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
diff --git a/config.go b/config.go
index 735b147..37045e9 100644
--- a/config.go
+++ b/config.go
@@ -4,14 +4,20 @@ import (
"fmt"
"io/ioutil"
"sort"
+ "strings"
- "gopkg.in/yaml.v2"
+ yaml "gopkg.in/yaml.v2"
)
+const _defaultGodocServer = "godoc.org"
+
// Config represents the structure of the yaml file
type Config struct {
URL string `yaml:"url"`
Packages map[string]Package `yaml:"packages"`
+ Godoc struct {
+ Host string `yaml:"host"`
+ } `yaml:"godoc"`
}
// Package details the options available for each repo
@@ -59,5 +65,15 @@ func Parse(path string) (*Config, error) {
return nil, fmt.Errorf("packages in %s must be alphabetically ordered", path)
}
+ if c.Godoc.Host == "" {
+ c.Godoc.Host = _defaultGodocServer
+ } else {
+ host := c.Godoc.Host
+ host = strings.TrimPrefix(host, "https://")
+ host = strings.TrimPrefix(host, "http://")
+ host = strings.TrimSuffix(host, "/")
+ c.Godoc.Host = host
+ }
+
return &c, err
}
diff --git a/config_test.go b/config_test.go
index 3bbe7e9..ab1bb2d 100644
--- a/config_test.go
+++ b/config_test.go
@@ -1,9 +1,11 @@
package main
import (
+ "fmt"
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestParse(t *testing.T) {
@@ -20,6 +22,7 @@ packages:
config, err := Parse(path)
assert.NoError(t, err)
+ assert.Equal(t, config.Godoc.Host, "godoc.org")
assert.Equal(t, config.URL, "google.golang.org")
pkg, ok := config.Packages["grpc"]
@@ -28,6 +31,42 @@ packages:
assert.Equal(t, pkg, Package{Repo: "github.com/grpc/grpc-go"})
}
+func TestParseGodocServer(t *testing.T) {
+ tests := []struct {
+ give string
+ want string
+ }{
+ {"example.com", "example.com"},
+ {"example.com/", "example.com"},
+ {"http://example.com/", "example.com"},
+ {"https://example.com/", "example.com"},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.give, func(t *testing.T) {
+ path, clean := TempFile(t, fmt.Sprintf(`
+godoc:
+ host: %q
+url: google.golang.org
+packages:
+ grpc:
+ repo: github.com/grpc/grpc-go
+`, tt.give))
+ defer clean()
+
+ config, err := Parse(path)
+ require.NoError(t, err)
+
+ assert.Equal(t, tt.want, config.Godoc.Host)
+ assert.Equal(t, "google.golang.org", config.URL)
+
+ pkg, ok := config.Packages["grpc"]
+ assert.True(t, ok)
+ assert.Equal(t, Package{Repo: "github.com/grpc/grpc-go"}, pkg)
+ })
+ }
+}
+
func TestNotAlphabetical(t *testing.T) {
path, clean := TempFile(t, `
diff --git a/handler.go b/handler.go
index 4c409fb..2f32132 100644
--- a/handler.go
+++ b/handler.go
@@ -60,7 +60,7 @@ func (h packageHandler) Handle(w http.ResponseWriter, r *http.Request, ps httpro
}{
Repo: h.pkg.Repo,
CanonicalURL: canonicalURL,
- GodocURL: fmt.Sprintf("https://godoc.org/%s%s", canonicalURL, ps.ByName("path")),
+ GodocURL: fmt.Sprintf("https://%s/%s%s", h.config.Godoc.Host, canonicalURL, ps.ByName("path")),
}
if err := packageTemplate.Execute(w, data); err != nil {
http.Error(w, err.Error(), 500)
diff --git a/templates/index.html b/templates/index.html
index 802996c..d322ef6 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -23,8 +23,8 @@
<a href="//{{ $value.Repo }}">{{ $value.Repo }}</a>
</td>
<td>
- <a href="//godoc.org/{{ $importPath }}">
- <img src="//godoc.org/{{ $importPath }}?status.svg" alt="GoDoc" />
+ <a href="//{{ $.Godoc.Host }}/{{ $importPath }}">
+ <img src="//{{ $.Godoc.Host }}/{{ $importPath }}?status.svg" alt="GoDoc" />
</a>
</td>
</tr>