2013-07-17 01:17:12 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package godoc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
Playground bool
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
|
2013-07-17 17:52:45 -06:00
|
|
|
func (p *Presentation) ServePage(w http.ResponseWriter, page Page) {
|
2013-07-17 01:17:12 -06:00
|
|
|
if page.Tabtitle == "" {
|
|
|
|
page.Tabtitle = page.Title
|
|
|
|
}
|
2013-07-17 17:52:45 -06:00
|
|
|
page.SearchBox = p.Corpus.IndexEnabled
|
2013-07-17 21:14:09 -06:00
|
|
|
page.Playground = p.ShowPlayground
|
2013-07-17 01:17:12 -06:00
|
|
|
page.Version = runtime.Version()
|
2013-07-17 21:51:17 -06:00
|
|
|
if err := p.GodocHTML.Execute(w, page); err != nil && err != http.ErrBodyNotAllowed {
|
2013-07-17 01:17:12 -06:00
|
|
|
// Only log if there's an error that's not about writing on HEAD requests.
|
|
|
|
// See Issues 5451 and 5454.
|
|
|
|
log.Printf("GodocHTML.Execute: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-17 17:52:45 -06:00
|
|
|
func (p *Presentation) ServeError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
|
2013-07-17 01:17:12 -06:00
|
|
|
w.WriteHeader(http.StatusNotFound)
|
2013-07-17 17:52:45 -06:00
|
|
|
p.ServePage(w, Page{
|
2013-07-17 01:17:12 -06:00
|
|
|
Title: "File " + relpath,
|
|
|
|
Subtitle: relpath,
|
2013-07-17 21:51:17 -06:00
|
|
|
Body: applyTemplate(p.ErrorHTML, "errorHTML", err), // err may contain an absolute path!
|
2013-07-17 01:17:12 -06:00
|
|
|
})
|
|
|
|
}
|