mirror of
https://github.com/golang/go
synced 2024-11-05 17:26:11 -07:00
e1d85eb8a3
These codes were initially included because of a miscommunication. They should not be in the list at all. Fixes golang/go#12747 Change-Id: I1a53e9c7be8edf5e1dbb95cd03101b93023a12c1 Reviewed-on: https://go-review.googlesource.com/15082 Reviewed-by: Andrew Gerrand <adg@golang.org>
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// 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 (
|
|
"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
|
|
Share bool
|
|
|
|
// filled in by servePage
|
|
SearchBox bool
|
|
Playground bool
|
|
Version string
|
|
}
|
|
|
|
func (p *Presentation) ServePage(w http.ResponseWriter, page Page) {
|
|
if page.Tabtitle == "" {
|
|
page.Tabtitle = page.Title
|
|
}
|
|
page.SearchBox = p.Corpus.IndexEnabled
|
|
page.Playground = p.ShowPlayground
|
|
page.Version = runtime.Version()
|
|
applyTemplateToResponseWriter(w, p.GodocHTML, page)
|
|
}
|
|
|
|
func (p *Presentation) ServeError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
p.ServePage(w, Page{
|
|
Title: "File " + relpath,
|
|
Subtitle: relpath,
|
|
Body: applyTemplate(p.ErrorHTML, "errorHTML", err), // err may contain an absolute path!
|
|
Share: allowShare(r),
|
|
})
|
|
}
|
|
|
|
var onAppengine = false // overriden in appengine.go when on app engine
|
|
|
|
func allowShare(r *http.Request) bool {
|
|
if !onAppengine {
|
|
return true
|
|
}
|
|
switch r.Header.Get("X-AppEngine-Country") {
|
|
case "", "ZZ", "CN":
|
|
return false
|
|
}
|
|
return true
|
|
}
|