1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 "golang.org/x/tools/godoc/golangorgenv"
17 // Page describes the contents of the top-level godoc webpage.
25 GoogleCN bool // page is being served from golang.google.cn
26 TreeView bool // page needs to contain treeview related js and css
28 // filled in by ServePage
32 GoogleAnalytics string
35 func (p *Presentation) ServePage(w http.ResponseWriter, page Page) {
36 if page.Tabtitle == "" {
37 page.Tabtitle = page.Title
39 page.SearchBox = p.Corpus.IndexEnabled
40 page.Playground = p.ShowPlayground
41 page.Version = runtime.Version()
42 page.GoogleAnalytics = p.GoogleAnalytics
43 applyTemplateToResponseWriter(w, p.GodocHTML, page)
46 func (p *Presentation) ServeError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
47 w.WriteHeader(http.StatusNotFound)
48 if perr, ok := err.(*os.PathError); ok {
49 rel, err := filepath.Rel(runtime.GOROOT(), perr.Path)
51 perr.Path = "REDACTED"
53 perr.Path = filepath.Join("$GOROOT", rel)
57 Title: "File " + relpath,
59 Body: applyTemplate(p.ErrorHTML, "errorHTML", err),
60 GoogleCN: googleCN(r),
61 GoogleAnalytics: p.GoogleAnalytics,
65 // googleCN reports whether request r is considered
66 // to be served from golang.google.cn.
67 func googleCN(r *http.Request) bool {
68 if r.FormValue("googlecn") != "" {
71 if strings.HasSuffix(r.Host, ".cn") {
74 if !golangorgenv.CheckCountry() {
77 switch r.Header.Get("X-Appengine-Country") {