diff --git a/cmd/godoc/.gitignore b/cmd/godoc/.gitignore deleted file mode 100644 index a02b5c6e..00000000 --- a/cmd/godoc/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -index.split.* -godoc.index -godoc.zip diff --git a/cmd/godoc/Dockerfile.prod b/cmd/godoc/Dockerfile.prod deleted file mode 100644 index f25d8807..00000000 --- a/cmd/godoc/Dockerfile.prod +++ /dev/null @@ -1,67 +0,0 @@ -# Builder -######### - -FROM golang:1.11 AS build - -RUN apt-get update && apt-get install -y \ - zip # required for generate-index.bash - -# Check out the desired version of Go, both to build the godoc binary and serve -# as the goroot for content serving. -ARG GO_REF -RUN test -n "$GO_REF" # GO_REF is required. -RUN git clone --single-branch --depth=1 -b $GO_REF https://go.googlesource.com/go /goroot -RUN cd /goroot/src && ./make.bash - -ENV GOROOT /goroot -ENV PATH=/goroot/bin:$PATH - -RUN go version - -RUN go get -v -d \ - golang.org/x/net/context \ - google.golang.org/appengine \ - cloud.google.com/go/datastore \ - golang.org/x/build \ - github.com/gomodule/redigo/redis - -COPY . /go/src/golang.org/x/tools - -WORKDIR /go/src/golang.org/x/tools/cmd/godoc -RUN GODOC_DOCSET=/goroot ./generate-index.bash - -RUN go build -o /godoc -tags=golangorg golang.org/x/tools/cmd/godoc - -# Clean up goroot for the final image. -RUN cd /goroot && git clean -xdf - -# Add build metadata. -RUN cd /goroot && echo "go repo HEAD: $(git rev-parse HEAD)" >> /goroot/buildinfo -RUN echo "requested go ref: ${GO_REF}" >> /goroot/buildinfo -ARG TOOLS_HEAD -RUN echo "x/tools HEAD: ${TOOLS_HEAD}" >> /goroot/buildinfo -ARG TOOLS_CLEAN -RUN echo "x/tools clean: ${TOOLS_CLEAN}" >> /goroot/buildinfo -ARG DOCKER_TAG -RUN echo "image: ${DOCKER_TAG}" >> /goroot/buildinfo -ARG BUILD_ENV -RUN echo "build env: ${BUILD_ENV}" >> /goroot/buildinfo - -RUN rm -rf /goroot/.git - -# Final image -############# - -FROM gcr.io/distroless/base - -WORKDIR /app -COPY --from=build /godoc /app/ -COPY --from=build /go/src/golang.org/x/tools/cmd/godoc/hg-git-mapping.bin /app/ - -COPY --from=build /goroot /goroot -ENV GOROOT /goroot - -COPY --from=build /go/src/golang.org/x/tools/cmd/godoc/index.split.* /app/ -ENV GODOC_INDEX_GLOB index.split.* - -CMD ["/app/godoc"] diff --git a/cmd/godoc/Makefile b/cmd/godoc/Makefile deleted file mode 100644 index df91d9a8..00000000 --- a/cmd/godoc/Makefile +++ /dev/null @@ -1,80 +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. - -.PHONY: usage - -GO_REF ?= release-branch.go1.11 -TOOLS_HEAD := $(shell git rev-parse HEAD) -TOOLS_CLEAN := $(shell (git status --porcelain | grep -q .) && echo dirty || echo clean) -ifeq ($(TOOLS_CLEAN),clean) - DOCKER_VERSION ?= $(TOOLS_HEAD) -else - DOCKER_VERSION ?= $(TOOLS_HEAD)-dirty -endif -GCP_PROJECT := golang-org -DOCKER_TAG := gcr.io/$(GCP_PROJECT)/godoc:$(DOCKER_VERSION) - -usage: - @echo "See Makefile and README.godoc-app" - @exit 1 - -cloud-build: Dockerfile.prod - gcloud builds submit \ - --project=$(GCP_PROJECT) \ - --config=cloudbuild.yaml \ - --substitutions=_GO_REF=$(GO_REF),_TOOLS_HEAD=$(TOOLS_HEAD),_TOOLS_CLEAN=$(TOOLS_CLEAN),_DOCKER_TAG=$(DOCKER_TAG) \ - ../.. # source code - -docker-build: Dockerfile.prod - # NOTE(cbro): move up in directory to include entire tools repo. - # NOTE(cbro): any changes made to this command must also be made in cloudbuild.yaml. - cd ../..; docker build \ - -f=cmd/godoc/Dockerfile.prod \ - --build-arg=GO_REF=$(GO_REF) \ - --build-arg=TOOLS_HEAD=$(TOOLS_HEAD) \ - --build-arg=TOOLS_CLEAN=$(TOOLS_CLEAN) \ - --build-arg=DOCKER_TAG=$(DOCKER_TAG) \ - --build-arg=BUILD_ENV=local \ - --tag=$(DOCKER_TAG) \ - . - -docker-push: docker-build - docker push $(DOCKER_TAG) - -deploy: - gcloud -q app deploy app.prod.yaml \ - --project=$(GCP_PROJECT) \ - --no-promote \ - --image-url=$(DOCKER_TAG) - -get-latest-url: - @gcloud app versions list \ - --service=default \ - --project=$(GCP_PROJECT) \ - --sort-by=~version.createTime \ - --format='value(version.versionUrl)' \ - --limit 1 | cut -f1 # NOTE(cbro): gcloud prints out createTime as the second field. - -get-latest-id: - @gcloud app versions list \ - --service=default \ - --project=$(GCP_PROJECT) \ - --sort-by=~version.createTime \ - --format='value(version.id)' \ - --limit 1 | cut -f1 # NOTE(cbro): gcloud prints out createTime as the second field. - -regtest: - go test -v \ - -regtest.host=$(shell make get-latest-url) \ - -run=Live - -publish: regtest - gcloud -q app services set-traffic default \ - --splits=$(shell make get-latest-id)=1 \ - --project=$(GCP_PROJECT) - - @echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - @echo Stop and/or delete old versions: - @echo "https://console.cloud.google.com/appengine/versions?project=$(GCP_PROJECT)&serviceId=default&versionssize=50" - @echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/cmd/godoc/README.godoc-app b/cmd/godoc/README.godoc-app deleted file mode 100644 index 5eba93a7..00000000 --- a/cmd/godoc/README.godoc-app +++ /dev/null @@ -1,94 +0,0 @@ -godoc on Google App Engine -========================== - -Prerequisites -------------- - -* Google Cloud SDK - https://cloud.google.com/sdk/ - -* Redis - -* Go sources under $GOROOT - -* Godoc sources inside $GOPATH - (go get -d golang.org/x/tools/cmd/godoc) - - -Running locally, in production mode ------------------------------------ - -Build the app: - - go build -tags golangorg - -Run the app: - - ./godoc - -godoc should come up at http://localhost:8080 - -Use the PORT environment variable to change the port: - - PORT=8081 ./godoc - -Running locally, in production mode, using Docker -------------------------------------------------- - -Build the app's Docker container: - - make docker-build - -Make sure redis is running on port 6379: - - $ echo PING | nc localhost 6379 - +PONG - ^C - -Run the datastore emulator: - - gcloud beta emulators datastore start --project golang-org - -In another terminal window, run the container: - - $(gcloud beta emulators datastore env-init) - - docker run --rm \ - --net host \ - --env GODOC_REDIS_ADDR=localhost:6379 \ - --env DATASTORE_EMULATOR_HOST=$DATASTORE_EMULATOR_HOST \ - --env DATASTORE_PROJECT_ID=$DATASTORE_PROJECT_ID \ - gcr.io/golang-org/godoc - -godoc should come up at http://localhost:8080 - - -Deploying to golang.org ------------------------ - -Make sure you're signed in to gcloud: - - gcloud auth login - -Build the image, push it to gcr.io, and deploy to Flex: - - make cloud-build deploy - -Point the load balancer to the newly deployed version: -(This also runs regression tests) - - make publish - -Stop and/or delete down any very old versions. (Stopped versions can be re-started.) -Keep at least one older verson to roll back to, just in case. -You can also migrate traffic to the new version via this UI. - - https://console.cloud.google.com/appengine/versions?project=golang-org&serviceId=default&versionssize=50 - - -Troubleshooting ---------------- - -Ensure the Cloud SDK is on your PATH and you have the app-engine-go component -installed (gcloud components install app-engine-go) and your components are -up-to-date (gcloud components update) diff --git a/cmd/godoc/app.dev.yaml b/cmd/godoc/app.dev.yaml deleted file mode 100644 index 0f8f1cc2..00000000 --- a/cmd/godoc/app.dev.yaml +++ /dev/null @@ -1,13 +0,0 @@ -runtime: go -api_version: go1 -instance_class: F4_1G - -handlers: -- url: /s - script: _go_app - login: admin -- url: /dl/init - script: _go_app - login: admin -- url: /.* - script: _go_app diff --git a/cmd/godoc/app.prod.yaml b/cmd/godoc/app.prod.yaml deleted file mode 100644 index 315c3dbc..00000000 --- a/cmd/godoc/app.prod.yaml +++ /dev/null @@ -1,16 +0,0 @@ -runtime: custom -env: flex - -env_variables: - GODOC_PROD: true - GODOC_ENFORCE_HOSTS: true - GODOC_REDIS_ADDR: 10.0.0.4:6379 # instance "gophercache" - GODOC_ANALYTICS: UA-11222381-2 - DATASTORE_PROJECT_ID: golang-org - -network: - name: golang - -resources: - cpu: 4 - memory_gb: 7.50 diff --git a/cmd/godoc/appinit.go b/cmd/godoc/appinit.go deleted file mode 100644 index 1f276d86..00000000 --- a/cmd/godoc/appinit.go +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2011 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. - -// +build golangorg - -package main - -// This file replaces main.go when running godoc under app-engine. -// See README.godoc-app for details. - -import ( - "archive/zip" - "context" - "io" - "log" - "net/http" - "os" - "path" - "regexp" - "runtime" - "strings" - - "golang.org/x/tools/godoc" - "golang.org/x/tools/godoc/dl" - "golang.org/x/tools/godoc/proxy" - "golang.org/x/tools/godoc/redirect" - "golang.org/x/tools/godoc/short" - "golang.org/x/tools/godoc/static" - "golang.org/x/tools/godoc/vfs" - "golang.org/x/tools/godoc/vfs/gatefs" - "golang.org/x/tools/godoc/vfs/mapfs" - "golang.org/x/tools/godoc/vfs/zipfs" - - "cloud.google.com/go/datastore" - "golang.org/x/tools/internal/memcache" -) - -func main() { - log.SetFlags(log.Lshortfile | log.LstdFlags) - - var ( - // .zip filename - zipFilename = os.Getenv("GODOC_ZIP") - - // goroot directory in .zip file - zipGoroot = os.Getenv("GODOC_ZIP_PREFIX") - - // glob pattern describing search index files - // (if empty, the index is built at run-time) - indexFilenames = os.Getenv("GODOC_INDEX_GLOB") - ) - - playEnabled = true - - log.Println("initializing godoc ...") - log.Printf(".zip file = %s", zipFilename) - log.Printf(".zip GOROOT = %s", zipGoroot) - log.Printf("index files = %s", indexFilenames) - - if zipFilename != "" { - goroot := path.Join("/", zipGoroot) // fsHttp paths are relative to '/' - // read .zip file and set up file systems - rc, err := zip.OpenReader(zipFilename) - if err != nil { - log.Fatalf("%s: %s\n", zipFilename, err) - } - // rc is never closed (app running forever) - fs.Bind("/", zipfs.New(rc, zipFilename), goroot, vfs.BindReplace) - } else { - rootfs := gatefs.New(vfs.OS(runtime.GOROOT()), make(chan bool, 20)) - fs.Bind("/", rootfs, "/", vfs.BindReplace) - } - - fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace) - - corpus := godoc.NewCorpus(fs) - corpus.Verbose = false - corpus.MaxResults = 10000 // matches flag default in main.go - corpus.IndexEnabled = true - corpus.IndexFiles = indexFilenames - if err := corpus.Init(); err != nil { - log.Fatal(err) - } - corpus.IndexDirectory = indexDirectoryDefault - corpus.InitVersionInfo() - if indexFilenames != "" { - corpus.RunIndexer() - } else { - go corpus.RunIndexer() - } - - pres = godoc.NewPresentation(corpus) - pres.TabWidth = 8 - pres.ShowPlayground = true - pres.DeclLinks = true - pres.NotesRx = regexp.MustCompile("BUG") - pres.GoogleAnalytics = os.Getenv("GODOC_ANALYTICS") - - readTemplates(pres) - - datastoreClient, memcacheClient := getClients() - - // NOTE(cbro): registerHandlers registers itself against DefaultServeMux. - // The mux returned has host enforcement, so it's important to register - // against this mux and not DefaultServeMux. - mux := registerHandlers(pres) - dl.RegisterHandlers(mux, datastoreClient, memcacheClient) - short.RegisterHandlers(mux, datastoreClient, memcacheClient) - - // Register /compile and /share handlers against the default serve mux - // so that other app modules can make plain HTTP requests to those - // hosts. (For reasons, HTTPS communication between modules is broken.) - proxy.RegisterHandlers(http.DefaultServeMux) - - http.HandleFunc("/_ah/health", func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, "ok") - }) - - http.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, "User-agent: *\nDisallow: /search\n") - }) - - if err := redirect.LoadChangeMap("hg-git-mapping.bin"); err != nil { - log.Fatalf("LoadChangeMap: %v", err) - } - - log.Println("godoc initialization complete") - - // TODO(cbro): add instrumentation via opencensus. - port := "8080" - if p := os.Getenv("PORT"); p != "" { // PORT is set by GAE flex. - port = p - } - log.Fatal(http.ListenAndServe(":"+port, nil)) -} - -func getClients() (*datastore.Client, *memcache.Client) { - ctx := context.Background() - - datastoreClient, err := datastore.NewClient(ctx, "") - if err != nil { - if strings.Contains(err.Error(), "missing project") { - log.Fatalf("Missing datastore project. Set the DATASTORE_PROJECT_ID env variable. Use `gcloud beta emulators datastore` to start a local datastore.") - } - log.Fatalf("datastore.NewClient: %v.", err) - } - - redisAddr := os.Getenv("GODOC_REDIS_ADDR") - if redisAddr == "" { - log.Fatalf("Missing redis server for godoc in production mode. set GODOC_REDIS_ADDR environment variable.") - } - memcacheClient := memcache.New(redisAddr) - return datastoreClient, memcacheClient -} diff --git a/cmd/godoc/autocert.go b/cmd/godoc/autocert.go deleted file mode 100644 index 9c2da414..00000000 --- a/cmd/godoc/autocert.go +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright 2016 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. - -// +build autocert - -// This file adds automatic TLS certificate support (using -// golang.org/x/crypto/acme/autocert), conditional on the use of the -// autocert build tag. It sets the serveAutoCertHook func variable -// non-nil. It is used by main.go. -// -// TODO: make this the default? We're in the Go 1.8 freeze now, so -// this is too invasive to be default, but we want it for -// https://beta.golang.org/ - -package main - -import ( - "crypto/tls" - "flag" - "net" - "net/http" - "time" - - "golang.org/x/crypto/acme/autocert" - "golang.org/x/net/http2" -) - -var ( - autoCertDirFlag = flag.String("autocert_cache_dir", "/var/cache/autocert", "Directory to cache TLS certs") - autoCertHostFlag = flag.String("autocert_hostname", "", "optional hostname to require in autocert SNI requests") -) - -func init() { - runHTTPS = runHTTPSAutocert - certInit = certInitAutocert - wrapHTTPMux = wrapHTTPMuxAutocert -} - -var autocertManager *autocert.Manager - -func certInitAutocert() { - autocertManager = &autocert.Manager{ - Cache: autocert.DirCache(*autoCertDirFlag), - Prompt: autocert.AcceptTOS, - } - if *autoCertHostFlag != "" { - autocertManager.HostPolicy = autocert.HostWhitelist(*autoCertHostFlag) - } -} - -func runHTTPSAutocert(h http.Handler) error { - srv := &http.Server{ - Handler: h, - TLSConfig: &tls.Config{ - GetCertificate: autocertManager.GetCertificate, - }, - IdleTimeout: 60 * time.Second, - } - http2.ConfigureServer(srv, &http2.Server{}) - ln, err := net.Listen("tcp", ":443") - if err != nil { - return err - } - return srv.Serve(tls.NewListener(tcpKeepAliveListener{ln.(*net.TCPListener)}, srv.TLSConfig)) -} - -func wrapHTTPMuxAutocert(h http.Handler) http.Handler { - return autocertManager.HTTPHandler(h) -} - -// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted -// connections. It's used by ListenAndServe and ListenAndServeTLS so -// dead TCP connections (e.g. closing laptop mid-download) eventually -// go away. -type tcpKeepAliveListener struct { - *net.TCPListener -} - -func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) { - tc, err := ln.AcceptTCP() - if err != nil { - return - } - tc.SetKeepAlive(true) - tc.SetKeepAlivePeriod(3 * time.Minute) - return tc, nil -} diff --git a/cmd/godoc/cloudbuild.yaml b/cmd/godoc/cloudbuild.yaml deleted file mode 100644 index fd297f07..00000000 --- a/cmd/godoc/cloudbuild.yaml +++ /dev/null @@ -1,25 +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. - -# NOTE(cbro): any changes to the docker command must also be -# made in docker-build in the Makefile. -# -# Variable substitutions must have a preceding underscore. See: -# https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values#using_user-defined_substitutions -steps: -- name: 'gcr.io/cloud-builders/docker' - args: [ - 'build', - '-f=cmd/godoc/Dockerfile.prod', - '--build-arg=GO_REF=${_GO_REF}', - '--build-arg=TOOLS_HEAD=${_TOOLS_HEAD}', - '--build-arg=TOOLS_CLEAN=${_TOOLS_CLEAN}', - '--build-arg=DOCKER_TAG=${_DOCKER_TAG}', - '--build-arg=BUILD_ENV=cloudbuild', - '--tag=${_DOCKER_TAG}', - '.', - ] -images: ['${_DOCKER_TAG}'] -options: - machineType: 'N1_HIGHCPU_8' # building the godoc index takes a lot of memory. diff --git a/cmd/godoc/dl.go b/cmd/godoc/dl.go index edeecb8a..962a0f01 100644 --- a/cmd/godoc/dl.go +++ b/cmd/godoc/dl.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build !golangorg - package main import "net/http" diff --git a/cmd/godoc/generate-index.bash b/cmd/godoc/generate-index.bash deleted file mode 100755 index 21b567a9..00000000 --- a/cmd/godoc/generate-index.bash +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2011 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. - -# This script creates a .zip file representing the $GOROOT file system -# and computes the corresponding search index files. -# -# These are used in production (see app.prod.yaml) - -set -e -u -x - -ZIPFILE=godoc.zip -INDEXFILE=godoc.index -SPLITFILES=index.split. - -error() { - echo "error: $1" - exit 2 -} - -install() { - go install -} - -getArgs() { - if [ ! -v GODOC_DOCSET ]; then - GODOC_DOCSET="$(go env GOROOT)" - echo "GODOC_DOCSET not set explicitly, using GOROOT instead" - fi - - # safety checks - if [ ! -d "$GODOC_DOCSET" ]; then - error "$GODOC_DOCSET is not a directory" - fi - - # reporting - echo "GODOC_DOCSET = $GODOC_DOCSET" -} - -makeZipfile() { - echo "*** make $ZIPFILE" - rm -f $ZIPFILE goroot - ln -s "$GODOC_DOCSET" goroot - zip -q -r $ZIPFILE goroot/* # glob to ignore dotfiles (like .git) - rm goroot -} - -makeIndexfile() { - echo "*** make $INDEXFILE" - godoc=$(go env GOPATH)/bin/godoc - # NOTE: run godoc without GOPATH set. Otherwise third-party packages will end up in the index. - GOPATH= $godoc -write_index -goroot goroot -index_files=$INDEXFILE -zip=$ZIPFILE -} - -splitIndexfile() { - echo "*** split $INDEXFILE" - rm -f $SPLITFILES* - split -b8m $INDEXFILE $SPLITFILES -} - -cd $(dirname $0) - -install -getArgs "$@" -makeZipfile -makeIndexfile -splitIndexfile -rm $INDEXFILE - -echo "*** setup complete" diff --git a/cmd/godoc/hg-git-mapping.bin b/cmd/godoc/hg-git-mapping.bin deleted file mode 100644 index 3f6ca77b..00000000 Binary files a/cmd/godoc/hg-git-mapping.bin and /dev/null differ diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index ac4509ad..0c28301a 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -15,8 +15,6 @@ // http://godoc/pkg/compress/zlib) // -// +build !golangorg - package main import ( diff --git a/cmd/godoc/play.go b/cmd/godoc/play.go index f44a3ccc..a899353e 100644 --- a/cmd/godoc/play.go +++ b/cmd/godoc/play.go @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build !golangorg - package main // This package registers "/compile" and "/share" handlers diff --git a/cmd/godoc/regtest_test.go b/cmd/godoc/regtest_test.go deleted file mode 100644 index f7c7219a..00000000 --- a/cmd/godoc/regtest_test.go +++ /dev/null @@ -1,171 +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. - -// Regression tests to run against a production instance of godoc. - -package main_test - -import ( - "bytes" - "flag" - "io" - "io/ioutil" - "net/http" - "net/url" - "regexp" - "strings" - "testing" -) - -var host = flag.String("regtest.host", "", "host to run regression test against") - -func init() { - flag.Parse() - *host = strings.TrimSuffix(*host, "/") -} - -func TestLiveServer(t *testing.T) { - if *host == "" { - t.Skip("regtest.host flag missing.") - } - substringTests := []struct { - Message string - Path string - Substring string - Regexp string - NoAnalytics bool // expect the response to not contain GA. - PostBody string - StatusCode int // if 0, expect 2xx status code. - }{ - { - Path: "/doc/faq", - Substring: "What is the purpose of the project", - }, - { - Path: "/pkg/", - Substring: "Package tar", - }, - { - Path: "/pkg/os/", - Substring: "func Open", - }, - { - Path: "/pkg/net/http/", - Substring: `title="Added in Go 1.11"`, - Message: "version information not present - failed InitVersionInfo?", - }, - { - Path: "/robots.txt", - Substring: "Disallow: /search", - Message: "robots not present - not deployed from Dockerfile?", - NoAnalytics: true, - }, - { - Path: "/change/75944e2e3a63", - Substring: "bdb10cf", - Message: "no change redirect - hg to git mapping not registered?", - NoAnalytics: true, - StatusCode: 302, - }, - { - Path: "/dl/", - Substring: "go1.11.windows-amd64.msi", - Message: "missing data on dl page - misconfiguration of datastore?", - }, - { - Path: "/dl/?mode=json", - Substring: ".windows-amd64.msi", - NoAnalytics: true, - }, - { - Message: "broken shortlinks - misconfiguration of datastore or memcache?", - Path: "/s/go2design", - Regexp: "proposal.*Found", - NoAnalytics: true, - StatusCode: 302, - }, - { - Message: "incorrect search result - broken index?", - Path: "/search?q=IsDir", - Substring: "src/os/types.go", - }, - { - Path: "/compile", - PostBody: "body=" + url.QueryEscape("package main; func main() { print(6*7); }"), - Regexp: `^{"compile_errors":"","output":"42"}$`, - NoAnalytics: true, - }, - { - Path: "/compile", - PostBody: "body=" + url.QueryEscape("//empty"), - Substring: "expected 'package', found 'EOF'", - NoAnalytics: true, - }, - { - Path: "/compile", - PostBody: "version=2&body=package+main%3Bimport+(%22fmt%22%3B%22time%22)%3Bfunc+main()%7Bfmt.Print(%22A%22)%3Btime.Sleep(time.Second)%3Bfmt.Print(%22B%22)%7D", - Regexp: `^{"Errors":"","Events":\[{"Message":"A","Kind":"stdout","Delay":0},{"Message":"B","Kind":"stdout","Delay":1000000000}\]}$`, - NoAnalytics: true, - }, - { - Path: "/share", - PostBody: "package main", - Substring: "", // just check it is a 2xx. - NoAnalytics: true, - }, - } - - for _, tc := range substringTests { - t.Run(tc.Path, func(t *testing.T) { - method := "GET" - var reqBody io.Reader - if tc.PostBody != "" { - method = "POST" - reqBody = strings.NewReader(tc.PostBody) - } - req, err := http.NewRequest(method, *host+tc.Path, reqBody) - if err != nil { - t.Fatalf("NewRequest: %v", err) - } - if reqBody != nil { - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - } - resp, err := http.DefaultTransport.RoundTrip(req) - if err != nil { - t.Fatalf("RoundTrip: %v", err) - } - if tc.StatusCode == 0 { - if resp.StatusCode > 299 { - t.Errorf("Non-OK status code: %v", resp.StatusCode) - } - } else if tc.StatusCode != resp.StatusCode { - t.Errorf("StatusCode; got %v, want %v", resp.StatusCode, tc.StatusCode) - } - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - t.Fatalf("ReadAll: %v", err) - } - - const googleAnalyticsID = "UA-11222381-2" // golang.org analytics ID - if !tc.NoAnalytics && !bytes.Contains(body, []byte(googleAnalyticsID)) { - t.Errorf("want response to contain analytics tracking ID") - } - - if tc.Substring != "" { - tc.Regexp = regexp.QuoteMeta(tc.Substring) - } - re := regexp.MustCompile(tc.Regexp) - - if !re.Match(body) { - t.Log("------ actual output -------") - t.Log(string(body)) - t.Log("----------------------------") - if tc.Message != "" { - t.Log(tc.Message) - } - t.Fatalf("wanted response to match %s", tc.Regexp) - } - }) - } -} diff --git a/cmd/godoc/x.go b/cmd/godoc/x.go deleted file mode 100644 index 3d624ca0..00000000 --- a/cmd/godoc/x.go +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2013 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. - -// This file contains the handlers that serve go-import redirects for Go -// sub-repositories. It specifies the mapping from import paths like -// "golang.org/x/tools" to the actual repository locations. - -package main - -import ( - "html/template" - "log" - "net/http" - "strings" -) - -const xPrefix = "/x/" - -type xRepo struct { - URL, VCS string -} - -var xMap = map[string]xRepo{ - "codereview": {"https://code.google.com/p/go.codereview", "hg"}, // Not included at https://golang.org/pkg/#subrepo. - - "arch": {"https://go.googlesource.com/arch", "git"}, // Not included at https://golang.org/pkg/#subrepo. - "benchmarks": {"https://go.googlesource.com/benchmarks", "git"}, - "blog": {"https://go.googlesource.com/blog", "git"}, - "build": {"https://go.googlesource.com/build", "git"}, - "crypto": {"https://go.googlesource.com/crypto", "git"}, - "debug": {"https://go.googlesource.com/debug", "git"}, - "exp": {"https://go.googlesource.com/exp", "git"}, - "image": {"https://go.googlesource.com/image", "git"}, - "lint": {"https://go.googlesource.com/lint", "git"}, // Not included at https://golang.org/pkg/#subrepo. - "mobile": {"https://go.googlesource.com/mobile", "git"}, - "net": {"https://go.googlesource.com/net", "git"}, - "oauth2": {"https://go.googlesource.com/oauth2", "git"}, // Not included at https://golang.org/pkg/#subrepo. - "perf": {"https://go.googlesource.com/perf", "git"}, - "playground": {"https://go.googlesource.com/playground", "git"}, // Not included at https://golang.org/pkg/#subrepo. - "review": {"https://go.googlesource.com/review", "git"}, - "sync": {"https://go.googlesource.com/sync", "git"}, - "sys": {"https://go.googlesource.com/sys", "git"}, - "talks": {"https://go.googlesource.com/talks", "git"}, // Not included at https://golang.org/pkg/#subrepo. - "term": {"https://go.googlesource.com/term", "git"}, // Not included at https://golang.org/pkg/#subrepo. - "text": {"https://go.googlesource.com/text", "git"}, - "time": {"https://go.googlesource.com/time", "git"}, - "tools": {"https://go.googlesource.com/tools", "git"}, - "tour": {"https://go.googlesource.com/tour", "git"}, - "vgo": {"https://go.googlesource.com/vgo", "git"}, // Not included at https://golang.org/pkg/#subrepo. - "website": {"https://go.googlesource.com/website", "git"}, // Not included at https://golang.org/pkg/#subrepo. - "xerrors": {"https://go.googlesource.com/xerrors", "git"}, // Not included at https://golang.org/pkg/#subrepo. -} - -func init() { - http.HandleFunc(xPrefix, xHandler) -} - -func xHandler(w http.ResponseWriter, r *http.Request) { - head, tail := strings.TrimPrefix(r.URL.Path, xPrefix), "" - if i := strings.Index(head, "/"); i != -1 { - head, tail = head[:i], head[i:] - } - if head == "" { - http.Redirect(w, r, "https://godoc.org/-/subrepo", http.StatusTemporaryRedirect) - return - } - repo, ok := xMap[head] - if !ok { - http.NotFound(w, r) - return - } - data := struct { - Prefix, Head, Tail string - Repo xRepo - }{xPrefix, head, tail, repo} - if err := xTemplate.Execute(w, data); err != nil { - log.Println("xHandler:", err) - } -} - -var xTemplate = template.Must(template.New("x").Parse(` - -
- - - - - - -Nothing to see here; move along. - - -`)) diff --git a/go.mod b/go.mod index 81d3648d..b8b0580f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module golang.org/x/tools require ( cloud.google.com/go v0.36.0 github.com/gomodule/redigo v2.0.0+incompatible - golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 golang.org/x/net v0.0.0-20190213061140-3a22650c66bd google.golang.org/appengine v1.4.0 ) diff --git a/go.sum b/go.sum index 7223f36a..91a0f442 100644 --- a/go.sum +++ b/go.sum @@ -92,8 +92,6 @@ go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d/go.mod h1:OWs+y06UdEOHN4y+MfF/py+xQ/tYqIWW03b70/CG9Rw= golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE= -golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=