diff options
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | gopherproxy.go | 17 |
2 files changed, 15 insertions, 4 deletions
@@ -3,7 +3,7 @@ FROM golang:alpine | |||
3 | EXPOSE 80/tcp | 3 | EXPOSE 80/tcp |
4 | 4 | ||
5 | ENTRYPOINT ["gopherproxy"] | 5 | ENTRYPOINT ["gopherproxy"] |
6 | CMD [] | 6 | CMD ["-bind", "0.0.0.0:80", "-uri", "floodgap.com"] |
7 | 7 | ||
8 | RUN \ | 8 | RUN \ |
9 | apk add --update git && \ | 9 | apk add --update git && \ |
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 |