all: make compatible with Go 1.15

With the help of the backported libraries introduced in the previous CL,
we can make the whole cmd/golangorg site run on Go 1.15 again.
This will let us use App Engine standard in advance of the release
of Go 1.16 on App Engine.

Change-Id: I9d1612de6f366e0774919aa6a94af14aafb248f5
Reviewed-on: https://go-review.googlesource.com/c/website/+/323891
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Russ Cox 2021-05-26 11:49:34 -04:00
Родитель 35beb4cf86
Коммит d831351689
42 изменённых файлов: 81 добавлений и 166 удалений

Просмотреть файл

@ -1,14 +0,0 @@
// Copyright 2021 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.
//go:build !go1.16
// +build !go1.16
package main
import "log"
func main() {
log.Fatalf("golangorg requires Go 1.16 or later")
}

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package main
import (

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package main_test
import (

Просмотреть файл

@ -2,18 +2,15 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package main
import (
"encoding/json"
"go/format"
"io/fs"
"net/http"
"strings"
"golang.org/x/website/internal/backport/io/fs"
"golang.org/x/website/internal/codewalk"
"golang.org/x/website/internal/env"
"golang.org/x/website/internal/redirect"

Просмотреть файл

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16 && !prod
// +build go1.16,!prod
//go:build !prod
// +build !prod
package main

Просмотреть файл

@ -15,21 +15,19 @@
// https://golang.org/pkg/compress/zlib)
//
//go:build go1.16
// +build go1.16
package main
import (
"flag"
"fmt"
"io/fs"
"log"
"net/http"
"os"
"runtime"
"golang.org/x/website"
"golang.org/x/website/internal/backport/io/fs"
"golang.org/x/website/internal/backport/osfs"
"golang.org/x/website/internal/web"
)
@ -72,11 +70,11 @@ func main() {
// Serve files from _content, falling back to GOROOT.
var content fs.FS
if *templateDir != "" {
content = os.DirFS(*templateDir)
content = osfs.DirFS(*templateDir)
} else {
content = website.Content
}
fsys = unionFS{content, os.DirFS(*goroot)}
fsys = unionFS{content, osfs.DirFS(*goroot)}
var err error
site, err = web.NewSite(fsys)

Просмотреть файл

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16 && prod
// +build go1.16,prod
//go:build prod
// +build prod
package main

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
// Regression tests to run against a production instance of golangorg.
package main_test

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package main
import (

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
// 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.
@ -12,12 +9,12 @@
package main
import (
"html/template"
"log"
"net/http"
"strings"
"golang.org/x/build/repos"
"golang.org/x/website/internal/backport/html/template"
)
func xHandler(w http.ResponseWriter, r *http.Request) {

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package main
import (

Просмотреть файл

@ -3,10 +3,11 @@ package main
import (
"fmt"
"html/template"
"net/http"
"os"
"strings"
"golang.org/x/website/internal/backport/html/template"
)
var repoMap = map[string]*repoImport{

Просмотреть файл

@ -2,22 +2,35 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
// Package website exports the static content as an embed.FS.
package website
import (
"embed"
"io/fs"
"os"
"golang.org/x/website/internal/backport/io/fs"
"golang.org/x/website/internal/backport/osfs"
)
// Content is the website's static content.
var Content = subdir(embedded, "_content")
var Content = findContent()
//go:embed _content
var embedded embed.FS
// TODO: Use with Go 1.16 in place of findContent call above.
// var Content = subdir(embedded, "_content")
// //go:embed _content
// var embedded embed.FS
func findContent() fs.FS {
// Walk parent directories looking for _content.
dir := "_content"
for i := 0; i < 10; i++ {
if _, err := os.Stat(dir + "/lib/godoc/godocs.js"); err == nil {
return osfs.DirFS(dir)
}
dir = "../" + dir
}
panic("cannot find _content")
}
func subdir(fsys fs.FS, path string) fs.FS {
s, err := fs.Sub(fsys, path)

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
// This file caches information about which standard library types, methods,
// and functions appeared in what version of Go
@ -12,13 +9,14 @@ package api
import (
"bufio"
"io/fs"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
"unicode"
"golang.org/x/website/internal/backport/io/fs"
)
// DB is a map of packages to information about those packages'

Просмотреть файл

@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package api
import (
"go/build"
"os"
"runtime"
"testing"
"golang.org/x/website/internal/backport/osfs"
)
func TestParseVersionRow(t *testing.T) {
@ -93,7 +91,7 @@ func hasTag(t string) bool {
}
func TestAPIVersion(t *testing.T) {
av, err := Load(os.DirFS(runtime.GOROOT()))
av, err := Load(osfs.DirFS(runtime.GOROOT()))
if err != nil {
t.Fatal(err)
}

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
// The /doc/codewalk/ tree is synthesized from codewalk descriptions,
// files named _content/doc/codewalk/*.xml.
// For an example and a description of the format, see
@ -19,9 +16,7 @@ import (
"encoding/xml"
"errors"
"fmt"
"html/template"
"io"
"io/fs"
"log"
"net/http"
"os"
@ -32,6 +27,8 @@ import (
"strings"
"unicode/utf8"
"golang.org/x/website/internal/backport/html/template"
"golang.org/x/website/internal/backport/io/fs"
"golang.org/x/website/internal/web"
)

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
// Package dl implements a simple downloads frontend server.
//
// It accepts HTTP POST requests to create a new download metadata entity, and

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package dl
import (

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package dl
import (

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package dl
import (

Просмотреть файл

@ -8,10 +8,11 @@ package history
import (
"fmt"
"html"
"html/template"
"sort"
"strings"
"time"
"golang.org/x/website/internal/backport/html/template"
)
// A Release describes a single Go release.

Просмотреть файл

@ -5,7 +5,7 @@
// Package history stores historical data for the Go project.
package history
import "html/template"
import "golang.org/x/website/internal/backport/html/template"
// Releases summarizes the changes between official stable releases of Go.
// It contains entries for all releases of Go, but releases older than Go 1.9

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
// This file contains the code dealing with package directory trees.
package pkgdoc
@ -15,11 +12,12 @@ import (
"go/doc"
"go/parser"
"go/token"
"io/fs"
"log"
"path"
"sort"
"strings"
"golang.org/x/website/internal/backport/io/fs"
)
type Dir struct {

Просмотреть файл

@ -2,22 +2,20 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package pkgdoc
import (
"go/token"
"os"
"runtime"
"sort"
"testing"
"testing/fstest"
"golang.org/x/website/internal/backport/osfs"
"golang.org/x/website/internal/backport/testing/fstest"
)
func TestNewDirTree(t *testing.T) {
dir := newDir(os.DirFS(runtime.GOROOT()), token.NewFileSet(), "src")
dir := newDir(osfs.DirFS(runtime.GOROOT()), token.NewFileSet(), "src")
processDir(t, dir)
}
@ -57,7 +55,7 @@ func BenchmarkNewDirectory(b *testing.B) {
b.Skip("not running tests requiring large file scan in short mode")
}
fs := os.DirFS(runtime.GOROOT())
fs := osfs.DirFS(runtime.GOROOT())
b.ResetTimer()
b.ReportAllocs()

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package pkgdoc
import (
@ -14,7 +11,6 @@ import (
"go/doc"
"go/token"
"io"
"io/fs"
"io/ioutil"
"log"
"os"
@ -24,6 +20,8 @@ import (
"strings"
"unicode"
"unicode/utf8"
"golang.org/x/website/internal/backport/io/fs"
)
type Docs struct {

Просмотреть файл

@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package pkgdoc
import (
"testing"
"testing/fstest"
"golang.org/x/website/internal/backport/testing/fstest"
)
// TestIgnoredGoFiles tests the scenario where a folder has no .go or .c files,

Просмотреть файл

@ -10,7 +10,6 @@ package redirect // import "golang.org/x/website/internal/redirect"
import (
"context"
"fmt"
"html/template"
"net/http"
"os"
"regexp"
@ -20,6 +19,7 @@ import (
"time"
"golang.org/x/net/context/ctxhttp"
"golang.org/x/website/internal/backport/html/template"
)
// Register registers HTTP handlers that redirect old godoc paths to their new

Просмотреть файл

@ -12,7 +12,6 @@ import (
"context"
"errors"
"fmt"
"html/template"
"log"
"net/http"
"net/url"
@ -20,6 +19,7 @@ import (
"strings"
"cloud.google.com/go/datastore"
"golang.org/x/website/internal/backport/html/template"
"golang.org/x/website/internal/memcache"
)

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
@ -14,12 +11,12 @@ import (
"go/doc"
"go/printer"
"go/token"
"html/template"
"io"
"log"
"unicode"
"golang.org/x/website/internal/api"
"golang.org/x/website/internal/backport/html/template"
"golang.org/x/website/internal/pkgdoc"
"golang.org/x/website/internal/texthtml"
)

Просмотреть файл

@ -2,21 +2,18 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
"bytes"
"fmt"
"html/template"
"io/fs"
"log"
"path"
"regexp"
"strings"
"golang.org/x/website/internal/backport/html/template"
"golang.org/x/website/internal/backport/io/fs"
"golang.org/x/website/internal/history"
"golang.org/x/website/internal/texthtml"
)

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
@ -12,12 +9,12 @@ import (
"go/ast"
"go/format"
"go/printer"
"html/template"
"log"
"regexp"
"strings"
"unicode/utf8"
"golang.org/x/website/internal/backport/html/template"
"golang.org/x/website/internal/pkgdoc"
)

Просмотреть файл

@ -2,18 +2,16 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
"bytes"
"encoding/json"
"io/fs"
"log"
"path"
"strings"
"golang.org/x/website/internal/backport/io/fs"
)
type file struct {
@ -45,7 +43,9 @@ func open(fsys fs.FS, relpath string) *file {
relpath = strings.TrimSuffix(relpath, "/")
}
files := []string{relpath + ".html", relpath + ".md", path.Join(relpath, "index.html"), path.Join(relpath, "index.md")}
// Check md before html to work correctly when x/website is layered atop Go 1.15 goroot during Go 1.15 tests.
// Want to find x/website's debugging_with_gdb.md not Go 1.15's debuging_with_gdb.html.
files := []string{relpath + ".md", relpath + ".html", path.Join(relpath, "index.md"), path.Join(relpath, "index.html")}
var filePath string
var b []byte
var err error

Просмотреть файл

@ -2,16 +2,14 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
"io/fs"
"path"
"strings"
"unicode/utf8"
"golang.org/x/website/internal/backport/io/fs"
)
// isText reports whether a significant prefix of s looks like correct UTF-8;

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (

Просмотреть файл

@ -2,18 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
"bytes"
"fmt"
"html"
"html/template"
"io"
"io/fs"
"log"
"net/http"
"path"
@ -23,6 +18,9 @@ import (
"strings"
"golang.org/x/website/internal/api"
"golang.org/x/website/internal/backport/html/template"
"golang.org/x/website/internal/backport/httpfs"
"golang.org/x/website/internal/backport/io/fs"
"golang.org/x/website/internal/pkgdoc"
"golang.org/x/website/internal/spec"
"golang.org/x/website/internal/texthtml"
@ -59,7 +57,7 @@ func NewSite(fsys fs.FS) (*Site, error) {
fs: fsys,
api: apiDB,
mux: http.NewServeMux(),
fileServer: http.FileServer(http.FS(fsys)),
fileServer: http.FileServer(httpfs.FS(fsys)),
}
docs := &docServer{
p: p,

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
@ -13,7 +10,8 @@ import (
"net/url"
"strings"
"testing"
"testing/fstest"
"golang.org/x/website/internal/backport/testing/fstest"
)
func testServeBody(t *testing.T, p *Site, path, body string) {

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
@ -14,10 +11,10 @@ import (
"go/doc"
"go/token"
"html"
"html/template"
"path"
"strings"
"golang.org/x/website/internal/backport/html/template"
"golang.org/x/website/internal/pkgdoc"
)

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import "io"

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web
import (
@ -12,10 +9,10 @@ import (
"fmt"
"go/parser"
"go/token"
"html/template"
"strings"
"testing"
"golang.org/x/website/internal/backport/html/template"
"golang.org/x/website/internal/pkgdoc"
)

Просмотреть файл

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
// Package webtest implements script-based testing for web servers.
//
// The scripts, described below, can be run against http.Handler
@ -155,10 +152,10 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
@ -192,7 +189,7 @@ func check(glob string, do func(*case_) error) error {
}
var buf bytes.Buffer
for _, file := range files {
data, err := os.ReadFile(file)
data, err := ioutil.ReadFile(file)
if err != nil {
fmt.Fprintf(&buf, "# %s\n%v\n", file, err)
continue
@ -244,7 +241,7 @@ func test(t *testing.T, glob string, do func(*case_) error) {
}
for _, file := range files {
t.Run(filepath.Base(file), func(t *testing.T) {
data, err := os.ReadFile(file)
data, err := ioutil.ReadFile(file)
if err != nil {
t.Fatal(err)
}
@ -345,7 +342,7 @@ func (c *case_) runServer(addr string) error {
if err != nil {
return fmt.Errorf("%s:%d: %s %s: %s", c.file, c.line, c.method, c.url, err)
}
body, err := io.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return fmt.Errorf("%s:%d: %s %s: reading body: %s", c.file, c.line, c.method, c.url, err)

Просмотреть файл

@ -2,16 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package webtest
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
@ -54,7 +51,7 @@ func testWebtest(t *testing.T, glob string, do func(*case_) error) {
}
for _, file := range files {
t.Run(filepath.Base(file), func(t *testing.T) {
data, err := os.ReadFile(file)
data, err := ioutil.ReadFile(file)
if err != nil {
t.Fatal(err)
}