Skip to content

Commit

Permalink
godoc: delete GoogleCN logic
Browse files Browse the repository at this point in the history
The GoogleCN code is specific to the code for golang.org,
which no longer uses golang.org/x/tools/godoc.

For #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>
  • Loading branch information
rsc committed Mar 12, 2021
1 parent 44abc2a commit 8e4f4c8
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 83 deletions.
8 changes: 3 additions & 5 deletions godoc/godoc.go
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand Down
42 changes: 0 additions & 42 deletions godoc/golangorgenv/golangorgenv.go

This file was deleted.

24 changes: 0 additions & 24 deletions godoc/page.go
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
}
1 change: 0 additions & 1 deletion godoc/search.go
Expand Up @@ -122,7 +122,6 @@ func (p *Presentation) HandleSearch(w http.ResponseWriter, r *http.Request) {
Tabtitle: query,
Query: query,
Body: body.Bytes(),
GoogleCN: googleCN(r),
})
}

Expand Down
5 changes: 0 additions & 5 deletions godoc/server.go
Expand Up @@ -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)
Expand All @@ -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,
})
}
Expand Down Expand Up @@ -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),
})
}

Expand Down Expand Up @@ -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),
})
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions godoc/static/example.html
Expand Up @@ -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}}
Expand Down
2 changes: 0 additions & 2 deletions godoc/static/godoc.html
Expand Up @@ -60,9 +60,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>
{{end}}
Expand Down
4 changes: 2 additions & 2 deletions godoc/static/static.go

Large diffs are not rendered by default.

0 comments on commit 8e4f4c8

Please sign in to comment.