Skip to content

Commit 66996d0

Browse files
committed
cmd/golangorg: simplify local vs prod programs
There was too much duplicated code between main.go and appinit.go and too many build-tagged-out files. Make main.go the func main for both prod and local. Introduce local.go, merging dl.go and play.go. Introduce prod.go, holding the prod-specific bits of appinit.go (the rest are in main.go). Rename the build tag to prod instead of golangorg (the whole program is golangorg; it's very confusing). Fixes golang/go#41102. Change-Id: I261ce8e9171110f01798025f8218ce9f8253af81 Reviewed-on: https://go-review.googlesource.com/c/website/+/293413 Trust: Russ Cox <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent fd7d167 commit 66996d0

21 files changed

+107
-260
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Content is in _content/. Server code is in cmd/ and internal/.
88

99
To run the server to preview local content changes, use:
1010

11-
go run ./cmd/golangorg -a
11+
go run ./cmd/golangorg
1212

1313
The supporting programs cmd/admingolangorg and cmd/googlegolangorg
1414
are the servers for admin.golang.org and google.golang.org.

cmd/golangorg/Dockerfile.prod

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ COPY . /website
2121

2222
WORKDIR /website/cmd/golangorg
2323

24-
RUN go build -o /golangorg -tags=golangorg golang.org/x/website/cmd/golangorg
24+
RUN go build -o /golangorg -tags=prod golang.org/x/website/cmd/golangorg
2525

2626
# Clean up goroot for the final image.
2727
RUN cd /goroot && git clean -xdf

cmd/golangorg/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ To run in production mode locally, you need:
1616
* Godoc sources inside $GOPATH
1717
(`go get -d golang.org/x/website/cmd/golangorg`)
1818

19-
Build with the `golangorg` tag and run:
19+
Run with the `prod` tag:
2020

21-
go build -tags golangorg
22-
./golangorg
21+
go run -tags prod .
2322

2423
In production mode it serves on localhost:8080 (not 6060).
2524
The port is controlled by $PORT, as in:

cmd/golangorg/blog.go

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.16
6+
// +build go1.16
7+
58
package main
69

710
import (

cmd/golangorg/codewalk.go

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.16
6+
// +build go1.16
7+
58
// The /doc/codewalk/ tree is synthesized from codewalk descriptions,
69
// files named $GOROOT/doc/codewalk/*.xml.
710
// For an example and a description of the format, see

cmd/golangorg/dl.go

-16
This file was deleted.

cmd/golangorg/go115.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build !go1.16
56
// +build !go1.16
67

78
package main

cmd/golangorg/godoc.go

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.16
6+
// +build go1.16
7+
58
package main
69

710
import (

cmd/golangorg/godoc_test.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build go1.16
56
// +build go1.16
67

78
package main_test
@@ -77,14 +78,6 @@ func waitForServerReady(t *testing.T, addr string) {
7778
false)
7879
}
7980

80-
func waitForSearchReady(t *testing.T, addr string) {
81-
waitForServer(t,
82-
fmt.Sprintf("http://%v/search?q=FALLTHROUGH", addr),
83-
"The list of tokens.",
84-
2*time.Minute,
85-
false)
86-
}
87-
8881
func waitUntilScanComplete(t *testing.T, addr string) {
8982
waitForServer(t,
9083
fmt.Sprintf("http://%v/pkg", addr),

cmd/golangorg/goroot.go

-74
This file was deleted.

cmd/golangorg/handlers.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
// The /doc/codewalk/ tree is synthesized from codewalk descriptions,
6-
// files named $GOROOT/doc/codewalk/*.xml.
7-
// For an example and a description of the format, see
8-
// http://golang.org/doc/codewalk/codewalk or run godoc -http=:6060
9-
// and see http://localhost:6060/doc/codewalk/codewalk .
10-
// That page is itself a codewalk; the source code for it is
11-
// $GOROOT/doc/codewalk/codewalk.xml.
5+
//go:build go1.16
6+
// +build go1.16
127

138
package main
149

cmd/golangorg/local.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2014 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.
4+
5+
//go:build go1.16 && !prod
6+
// +build go1.16,!prod
7+
8+
package main
9+
10+
import (
11+
"fmt"
12+
"log"
13+
"net/http"
14+
"os"
15+
"path/filepath"
16+
"runtime"
17+
18+
// This package registers "/compile" and "/share" handlers
19+
// that redirect to the golang.org playground.
20+
_ "golang.org/x/tools/playground"
21+
)
22+
23+
func earlySetup() {
24+
_, file, _, ok := runtime.Caller(0)
25+
if !ok {
26+
fmt.Fprintln(os.Stderr, "runtime.Caller failed: cannot find templates for -a mode.")
27+
os.Exit(2)
28+
}
29+
dir := filepath.Join(file, "../../../_content")
30+
if _, err := os.Stat(filepath.Join(dir, "godoc.html")); err != nil {
31+
log.Printf("warning: cannot find template dir; using embedded copy")
32+
return
33+
}
34+
*templateDir = dir
35+
}
36+
37+
func lateSetup(mux *http.ServeMux) {
38+
// Register a redirect handler for /dl/ to the golang.org download page.
39+
http.Handle("/dl/", http.RedirectHandler("https://golang.org/dl/", http.StatusFound))
40+
}

0 commit comments

Comments
 (0)