cmd/golangorg: remove -url flag

The -url flag is unused. It had relatively niche
use-cases and was mostly a relic from cmd/godoc.

It's also completely non-functional due to a few bugs and
the fact CL 162907 hasn't been backported to x/website.

Instead of fixing it and adding tests, remove it.
If it becomes needed in the future, it can be re-added.

Update golang/go#29206

Change-Id: I4a460f460a757c78c3e26d7c97556c623c8dbed4
Reviewed-on: https://go-review.googlesource.com/c/website/+/197722
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
diff --git a/cmd/golangorg/appinit.go b/cmd/golangorg/appinit.go
index 5b9e8aa..5485194 100644
--- a/cmd/golangorg/appinit.go
+++ b/cmd/golangorg/appinit.go
@@ -54,7 +54,7 @@
 
 	playEnabled = true
 
-	log.Println("initializing godoc ...")
+	log.Println("initializing golang.org server ...")
 	log.Printf(".zip file   = %s", zipFilename)
 	log.Printf(".zip GOROOT = %s", zipGoroot)
 	log.Printf("index files = %s", indexFilenames)
diff --git a/cmd/golangorg/doc.go b/cmd/golangorg/doc.go
index 469fb82..3ece91f 100644
--- a/cmd/golangorg/doc.go
+++ b/cmd/golangorg/doc.go
@@ -56,9 +56,6 @@
 		directory containing alternate template files; if set,
 		the directory may provide alternative template files
 		for the files in $GOROOT/lib/godoc
-	-url=path
-		print to standard output the data that would be served by
-		an HTTP request for path
 	-zip=""
 		zip file providing the file system to serve; disabled if empty
 
diff --git a/cmd/golangorg/godoc_test.go b/cmd/golangorg/godoc_test.go
index 5a90234..7a17b34 100644
--- a/cmd/golangorg/godoc_test.go
+++ b/cmd/golangorg/godoc_test.go
@@ -151,7 +151,7 @@
 // Basic integration test for godoc HTTP interface.
 func testWeb(t *testing.T, withIndex bool) {
 	if runtime.GOOS == "plan9" {
-		t.Skip("skipping on plan9; files to start up quickly enough")
+		t.Skip("skipping on plan9; fails to start up quickly enough")
 	}
 	bin, cleanup := buildGodoc(t)
 	defer cleanup()
diff --git a/cmd/golangorg/main.go b/cmd/golangorg/main.go
index b4665e4..1044f7f 100644
--- a/cmd/golangorg/main.go
+++ b/cmd/golangorg/main.go
@@ -24,7 +24,6 @@
 
 import (
 	"archive/zip"
-	"bytes"
 	_ "expvar" // to serve /debug/vars
 	"flag"
 	"fmt"
@@ -32,7 +31,6 @@
 	"log"
 	"net/http"
 	_ "net/http/pprof" // to serve /debug/pprof/*
-	"net/url"
 	"os"
 	"path/filepath"
 	"regexp"
@@ -59,9 +57,6 @@
 	// network
 	httpAddr = flag.String("http", defaultAddr, "HTTP service address")
 
-	// layout control
-	urlFlag = flag.String("url", "", "print HTML for named URL")
-
 	verbose = flag.Bool("v", false, "verbose mode")
 
 	// file system roots
@@ -93,17 +88,6 @@
 	return gopath + relPath
 }
 
-// An httpResponseRecorder is an http.ResponseWriter
-type httpResponseRecorder struct {
-	body   *bytes.Buffer
-	header http.Header
-	code   int
-}
-
-func (w *httpResponseRecorder) Header() http.Header         { return w.header }
-func (w *httpResponseRecorder) Write(b []byte) (int, error) { return len(b), nil }
-func (w *httpResponseRecorder) WriteHeader(code int)        { w.code = code }
-
 func usage() {
 	fmt.Fprintf(os.Stderr, "usage: golangorg -http="+defaultAddr+"\n")
 	flag.PrintDefaults()
@@ -117,42 +101,6 @@
 	})
 }
 
-func handleURLFlag() {
-	// Try up to 10 fetches, following redirects.
-	urlstr := *urlFlag
-	for i := 0; i < 10; i++ {
-		// Prepare request.
-		u, err := url.Parse(urlstr)
-		if err != nil {
-			log.Fatal(err)
-		}
-		req := &http.Request{
-			URL: u,
-		}
-
-		// Invoke default HTTP handler to serve request
-		// to our buffering httpWriter.
-		w := &httpResponseRecorder{code: 200, header: make(http.Header), body: new(bytes.Buffer)}
-		http.DefaultServeMux.ServeHTTP(w, req)
-
-		// Return data, error, or follow redirect.
-		switch w.code {
-		case 200: // ok
-			os.Stdout.Write(w.body.Bytes())
-			return
-		case 301, 302, 303, 307: // redirect
-			redirect := w.header.Get("Location")
-			if redirect == "" {
-				log.Fatalf("HTTP %d without Location header", w.code)
-			}
-			urlstr = redirect
-		default:
-			log.Fatalf("HTTP error %d", w.code)
-		}
-	}
-	log.Fatalf("too many redirects")
-}
-
 func initCorpus(corpus *godoc.Corpus) {
 	err := corpus.Init()
 	if err != nil {
@@ -166,15 +114,13 @@
 
 	playEnabled = *showPlayground
 
-	// Check usage: server and no args.
-	if (*httpAddr != "" || *urlFlag != "") && (flag.NArg() > 0) {
+	// Check usage.
+	if flag.NArg() > 0 {
 		fmt.Fprintln(os.Stderr, "Unexpected arguments.")
 		usage()
 	}
-
-	// Check usage: command line args or index creation mode.
-	if (*httpAddr != "" || *urlFlag != "") != (flag.NArg() == 0) && !*writeIndex {
-		fmt.Fprintln(os.Stderr, "missing args.")
+	if *httpAddr == "" && !*writeIndex {
+		fmt.Fprintln(os.Stderr, "At least one of -http or -write_index must be set to a non-zero value.")
 		usage()
 	}
 
@@ -278,15 +224,9 @@
 		return
 	}
 
-	// Print content that would be served at the URL *urlFlag.
-	if *urlFlag != "" {
-		handleURLFlag()
-		return
-	}
-
 	var handler http.Handler = http.DefaultServeMux
 	if *verbose {
-		log.Printf("Go Documentation Server")
+		log.Printf("golang.org server")
 		log.Printf("version = %s", runtime.Version())
 		log.Printf("address = %s", *httpAddr)
 		log.Printf("goroot = %s", *goroot)