diff options
author | James Mills <prologic@shortcircuit.net.au> | 2017-06-26 01:48:07 -0700 |
---|---|---|
committer | James Mills <prologic@shortcircuit.net.au> | 2017-06-26 01:48:07 -0700 |
commit | da3c29209fb9519913f5eb4fcc1b1a4986464f03 (patch) | |
tree | fa1f0c14a9bf6a421d6e57cea6540a72b4308854 /gopherproxy.go | |
parent | Add gorelease config to travis for automated binary releases (diff) | |
download | gopherproxy-da3c29209fb9519913f5eb4fcc1b1a4986464f03.tar.gz gopherproxy-da3c29209fb9519913f5eb4fcc1b1a4986464f03.tar.bz2 gopherproxy-da3c29209fb9519913f5eb4fcc1b1a4986464f03.zip |
Bump
Diffstat (limited to 'gopherproxy.go')
-rw-r--r-- | gopherproxy.go | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/gopherproxy.go b/gopherproxy.go index 8c85448..fcce1ee 100644 --- a/gopherproxy.go +++ b/gopherproxy.go | |||
@@ -23,9 +23,16 @@ type tplRow struct { | |||
23 | type Handler func(w http.ResponseWriter, req *http.Request) | 23 | type Handler func(w http.ResponseWriter, req *http.Request) |
24 | 24 | ||
25 | func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport string, d gopher.Directory) error { | 25 | func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport string, d gopher.Directory) error { |
26 | out := make([]tplRow, len(d)) | 26 | var title string |
27 | |||
28 | out := make([]tplRow, len(d.Items)) | ||
29 | |||
30 | for i, x := range d.Items { | ||
31 | if x.Type == gopher.INFO && x.Selector == "TITLE" { | ||
32 | title = x.Description | ||
33 | continue | ||
34 | } | ||
27 | 35 | ||
28 | for i, x := range d { | ||
29 | tr := tplRow{ | 36 | tr := tplRow{ |
30 | Text: x.Description, | 37 | Text: x.Description, |
31 | Type: x.Type.String(), | 38 | Type: x.Type.String(), |
@@ -60,10 +67,14 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, hostport str | |||
60 | out[i] = tr | 67 | out[i] = tr |
61 | } | 68 | } |
62 | 69 | ||
70 | if title == "" { | ||
71 | title = hostport | ||
72 | } | ||
73 | |||
63 | return tpl.Execute(w, struct { | 74 | return tpl.Execute(w, struct { |
64 | Title string | 75 | Title string |
65 | Lines []tplRow | 76 | Lines []tplRow |
66 | }{hostport, out}) | 77 | }{title, out}) |
67 | } | 78 | } |
68 | 79 | ||
69 | // MakeGopherProxyHandler returns a Handler that proxies requests | 80 | // MakeGopherProxyHandler returns a Handler that proxies requests |