diff options
Diffstat (limited to 'gopherproxy.go')
-rw-r--r-- | gopherproxy.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/gopherproxy.go b/gopherproxy.go index 961806a..8ba515e 100644 --- a/gopherproxy.go +++ b/gopherproxy.go | |||
@@ -25,7 +25,7 @@ type Item struct { | |||
25 | Text string | 25 | Text string |
26 | } | 26 | } |
27 | 27 | ||
28 | func renderDirectory(w http.ResponseWriter, tpl *template.Template, styletext string, hostport string, d gopher.Directory) error { | 28 | func renderDirectory(w http.ResponseWriter, tpl *template.Template, styletext string, uri string, hostport string, d gopher.Directory) error { |
29 | var title string | 29 | var title string |
30 | 30 | ||
31 | out := make([]Item, len(d.Items)) | 31 | out := make([]Item, len(d.Items)) |
@@ -76,10 +76,11 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, styletext st | |||
76 | 76 | ||
77 | return tpl.Execute(w, struct { | 77 | return tpl.Execute(w, struct { |
78 | Title string | 78 | Title string |
79 | URI string | ||
79 | Style string | 80 | Style string |
80 | Lines []Item | 81 | Lines []Item |
81 | RawText string | 82 | RawText string |
82 | }{title, styletext, out, ""}) | 83 | }{title, fmt.Sprintf("%s/%s", hostport, uri), styletext, out, ""}) |
83 | } | 84 | } |
84 | 85 | ||
85 | // GopherHandler returns a Handler that proxies requests | 86 | // GopherHandler returns a Handler that proxies requests |
@@ -137,15 +138,16 @@ func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, rob | |||
137 | buf.ReadFrom(res.Body) | 138 | buf.ReadFrom(res.Body) |
138 | tpl.Execute(w, struct { | 139 | tpl.Execute(w, struct { |
139 | Title string | 140 | Title string |
141 | URI string | ||
140 | Style string | 142 | Style string |
141 | RawText string | 143 | RawText string |
142 | Lines []Item | 144 | Lines []Item |
143 | }{uri, styletext, buf.String(), nil}) | 145 | }{uri, fmt.Sprintf("%s/%s", hostport, uri), styletext, buf.String(), nil}) |
144 | } else { | 146 | } else { |
145 | io.Copy(w, res.Body) | 147 | io.Copy(w, res.Body) |
146 | } | 148 | } |
147 | } else { | 149 | } else { |
148 | if err := renderDirectory(w, tpl, styletext, hostport, res.Dir); err != nil { | 150 | if err := renderDirectory(w, tpl, styletext, uri, hostport, res.Dir); err != nil { |
149 | io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) | 151 | io.WriteString(w, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) |
150 | return | 152 | return |
151 | } | 153 | } |
@@ -258,6 +260,13 @@ func ListenAndServe(bind, robotsfile string, robotsdebug bool, uri string) error | |||
258 | "HTMLEscape": func(s string) string { | 260 | "HTMLEscape": func(s string) string { |
259 | return html.EscapeString(s) | 261 | return html.EscapeString(s) |
260 | }, | 262 | }, |
263 | "split": strings.Split, | ||
264 | "last": func(s []string) string { | ||
265 | return s[len(s)-1] | ||
266 | }, | ||
267 | "pop": func(s []string) []string { | ||
268 | return s[:len(s)-1] | ||
269 | }, | ||
261 | } | 270 | } |
262 | 271 | ||
263 | tpl, err = template.New("gophermenu").Funcs(funcMap).Parse(tpltext) | 272 | tpl, err = template.New("gophermenu").Funcs(funcMap).Parse(tpltext) |