godoc: delete GoogleCN logic

The GoogleCN code is specific to the code for golang.org,
which no longer uses golang.org/x/tools/godoc.

For golang/go#32011.

Change-Id: If13e3ed93d57f9d8a6c0f8a09b8343567dd6c0b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/296373
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Russ Cox 2021-02-25 10:28:37 -05:00
parent 44abc2a71b
commit 8e4f4c8659
8 changed files with 5 additions and 83 deletions

View File

@ -398,9 +398,8 @@ func sanitizeFunc(src string) string {
}
type PageInfo struct {
Dirname string // directory containing the package
Err error // error or nil
GoogleCN bool // page is being served from golang.google.cn
Dirname string // directory containing the package
Err error // error or nil
Mode PageInfoMode // display metadata from query string
@ -614,8 +613,7 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string
err := p.ExampleHTML.Execute(&buf, struct {
Name, Doc, Code, Play, Output string
GoogleCN bool
}{eg.Name, eg.Doc, code, play, out, info.GoogleCN})
}{eg.Name, eg.Doc, code, play, out})
if err != nil {
log.Print(err)
}

View File

@ -1,42 +0,0 @@
// Copyright 2018 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 golangorgenv provides environment information for programs running at
// golang.org and its subdomains.
package golangorgenv
import (
"log"
"os"
"strconv"
)
var (
checkCountry = boolEnv("GOLANGORG_CHECK_COUNTRY")
enforceHosts = boolEnv("GOLANGORG_ENFORCE_HOSTS")
)
// CheckCountry reports whether country restrictions should be enforced.
func CheckCountry() bool {
return checkCountry
}
// EnforceHosts reports whether host filtering should be enforced.
func EnforceHosts() bool {
return enforceHosts
}
func boolEnv(key string) bool {
v := os.Getenv(key)
if v == "" {
// TODO(dmitshur): In the future, consider detecting if running in App Engine,
// and if so, making the environment variables mandatory rather than optional.
return false
}
b, err := strconv.ParseBool(v)
if err != nil {
log.Fatalf("environment variable %s (%q) must be a boolean", key, v)
}
return b
}

View File

@ -9,9 +9,6 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
"golang.org/x/tools/godoc/golangorgenv"
)
// Page describes the contents of the top-level godoc webpage.
@ -22,7 +19,6 @@ type Page struct {
SrcPath string
Query string
Body []byte
GoogleCN bool // page is being served from golang.google.cn
TreeView bool // page needs to contain treeview related js and css
// filled in by ServePage
@ -57,26 +53,6 @@ func (p *Presentation) ServeError(w http.ResponseWriter, r *http.Request, relpat
Title: "File " + relpath,
Subtitle: relpath,
Body: applyTemplate(p.ErrorHTML, "errorHTML", err),
GoogleCN: googleCN(r),
GoogleAnalytics: p.GoogleAnalytics,
})
}
// googleCN reports whether request r is considered
// to be served from golang.google.cn.
func googleCN(r *http.Request) bool {
if r.FormValue("googlecn") != "" {
return true
}
if strings.HasSuffix(r.Host, ".cn") {
return true
}
if !golangorgenv.CheckCountry() {
return false
}
switch r.Header.Get("X-Appengine-Country") {
case "", "ZZ", "CN":
return true
}
return false
}

View File

@ -122,7 +122,6 @@ func (p *Presentation) HandleSearch(w http.ResponseWriter, r *http.Request) {
Tabtitle: query,
Query: query,
Body: body.Bytes(),
GoogleCN: googleCN(r),
})
}

View File

@ -328,7 +328,6 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
info.TypeInfoIndex[ti.Name] = i
}
info.GoogleCN = googleCN(r)
var body []byte
if info.Dirname == "/src" {
body = applyTemplate(h.p.PackageRootHTML, "packageRootHTML", info)
@ -340,7 +339,6 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Tabtitle: tabtitle,
Subtitle: subtitle,
Body: body,
GoogleCN: info.GoogleCN,
TreeView: hasTreeView,
})
}
@ -610,7 +608,6 @@ func (p *Presentation) serveTextFile(w http.ResponseWriter, r *http.Request, abs
SrcPath: relpath,
Tabtitle: relpath,
Body: buf.Bytes(),
GoogleCN: googleCN(r),
})
}
@ -689,7 +686,6 @@ func (p *Presentation) serveDirectory(w http.ResponseWriter, r *http.Request, ab
SrcPath: relpath,
Tabtitle: relpath,
Body: applyTemplate(p.DirlistHTML, "dirlistHTML", list),
GoogleCN: googleCN(r),
})
}
@ -726,7 +722,6 @@ func (p *Presentation) ServeHTMLDoc(w http.ResponseWriter, r *http.Request, absp
page := Page{
Title: meta.Title,
Subtitle: meta.Subtitle,
GoogleCN: googleCN(r),
}
// evaluate as template if indicated

View File

@ -13,9 +13,7 @@
<div class="buttons">
<a class="run" title="Run this code [shift-enter]">Run</a>
<a class="fmt" title="Format this code">Format</a>
{{if not $.GoogleCN}}
<a class="share" title="Share this code">Share</a>
{{end}}
</div>
</div>
{{else}}

View File

@ -60,9 +60,7 @@ func main() {
<div class="buttons">
<a class="run" title="Run this code [shift-enter]">Run</a>
<a class="fmt" title="Format this code">Format</a>
{{if not $.GoogleCN}}
<a class="share" title="Share this code">Share</a>
{{end}}
</div>
</div>
{{end}}

File diff suppressed because one or more lines are too long