return
}
- b := applyTemplate(codewalkHTML, "codewalk", cw)
- servePage(w, cw.Title, "Codewalk: "+cw.Title, "", "", b)
+ servePage(w, Page{
+ Title: "Codewalk: " + cw.Title,
+ Tabtitle: cw.Title,
+ Body: applyTemplate(codewalkHTML, "codewalk", cw),
+ })
}
// A Codewalk represents a single codewalk read from an XML file.
}
}
- b := applyTemplate(codewalkdirHTML, "codewalkdir", v)
- servePage(w, "", "Codewalks", "", "", b)
+ servePage(w, Page{
+ Title: "Codewalks",
+ Body: applyTemplate(codewalkdirHTML, "codewalkdir", v),
+ })
}
// codewalkFileprint serves requests with ?fileprint=f&lo=lo&hi=hi.
// ----------------------------------------------------------------------------
// Generic HTML wrapper
-func servePage(w http.ResponseWriter, tabtitle, title, subtitle, query string, content []byte) {
- if tabtitle == "" {
- tabtitle = title
- }
- d := struct {
- Tabtitle string
- Title string
- Subtitle string
- SearchBox bool
- Query string
- Version string
- Menu []byte
- Content []byte
- }{
- tabtitle,
- title,
- subtitle,
- *indexEnabled,
- query,
- runtime.Version(),
- nil,
- content,
- }
-
- if err := godocHTML.Execute(w, &d); err != nil {
+// Page describes the contents of the top-level godoc webpage.
+type Page struct {
+ Title string
+ Tabtitle string
+ Subtitle string
+ Query string
+ Body []byte
+
+ // filled in by servePage
+ SearchBox bool
+ Version string
+}
+
+func servePage(w http.ResponseWriter, page Page) {
+ if page.Tabtitle == "" {
+ page.Tabtitle = page.Title
+ }
+ page.SearchBox = *indexEnabled
+ page.Version = runtime.Version()
+ if err := godocHTML.Execute(w, page); err != nil {
log.Printf("godocHTML.Execute: %s", err)
}
}
src = buf.Bytes()
}
- servePage(w, "", meta.Title, meta.Subtitle, "", src)
+ servePage(w, Page{
+ Title: meta.Title,
+ Subtitle: meta.Subtitle,
+ Body: src,
+ })
}
func applyTemplate(t *template.Template, name string, data interface{}) []byte {
FormatText(&buf, src, 1, pathpkg.Ext(abspath) == ".go", r.FormValue("h"), rangeSelection(r.FormValue("s")))
buf.WriteString("</pre>")
- servePage(w, relpath, title+" "+relpath, "", "", buf.Bytes())
+ servePage(w, Page{
+ Title: title + " " + relpath,
+ Tabtitle: relpath,
+ Body: buf.Bytes(),
+ })
}
func serveDirectory(w http.ResponseWriter, r *http.Request, abspath, relpath string) {
return
}
- contents := applyTemplate(dirlistHTML, "dirlistHTML", list)
- servePage(w, relpath, "Directory "+relpath, "", "", contents)
+ servePage(w, Page{
+ Title: "Directory " + relpath,
+ Tabtitle: relpath,
+ Body: applyTemplate(dirlistHTML, "dirlistHTML", list),
+ })
}
func serveFile(w http.ResponseWriter, r *http.Request) {
}
if mode&noHtml != 0 {
- contents := applyTemplate(packageText, "packageText", info)
- serveText(w, contents)
+ serveText(w, applyTemplate(packageText, "packageText", info))
return
}
tabtitle = "Commands"
}
- contents := applyTemplate(packageHTML, "packageHTML", info)
- servePage(w, tabtitle, title, subtitle, "", contents)
+ servePage(w, Page{
+ Title: title,
+ Tabtitle: tabtitle,
+ Subtitle: subtitle,
+ Body: applyTemplate(packageHTML, "packageHTML", info),
+ })
}
// ----------------------------------------------------------------------------
result := lookup(query)
if getPageInfoMode(r)&noHtml != 0 {
- contents := applyTemplate(searchText, "searchText", result)
- serveText(w, contents)
+ serveText(w, applyTemplate(searchText, "searchText", result))
return
}
title = fmt.Sprintf(`No results found for query %q`, query)
}
- contents := applyTemplate(searchHTML, "searchHTML", result)
- servePage(w, query, title, "", query, contents)
+ servePage(w, Page{
+ Title: title,
+ Tabtitle: query,
+ Query: query,
+ Body: applyTemplate(searchHTML, "searchHTML", result),
+ })
}
// ----------------------------------------------------------------------------