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 // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package main package main
import ( import (

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

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

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

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

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

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

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

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

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

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

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

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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. // Regression tests to run against a production instance of golangorg.
package main_test package main_test

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

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

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

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 // This file contains the handlers that serve go-import redirects for Go
// sub-repositories. It specifies the mapping from import paths like // sub-repositories. It specifies the mapping from import paths like
// "golang.org/x/tools" to the actual repository locations. // "golang.org/x/tools" to the actual repository locations.
@ -12,12 +9,12 @@
package main package main
import ( import (
"html/template"
"log" "log"
"net/http" "net/http"
"strings" "strings"
"golang.org/x/build/repos" "golang.org/x/build/repos"
"golang.org/x/website/internal/backport/html/template"
) )
func xHandler(w http.ResponseWriter, r *http.Request) { func xHandler(w http.ResponseWriter, r *http.Request) {

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

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

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

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

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

@ -2,22 +2,35 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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 exports the static content as an embed.FS.
package website package website
import ( import (
"embed" "os"
"io/fs"
"golang.org/x/website/internal/backport/io/fs"
"golang.org/x/website/internal/backport/osfs"
) )
// Content is the website's static content. // Content is the website's static content.
var Content = subdir(embedded, "_content") var Content = findContent()
//go:embed _content // TODO: Use with Go 1.16 in place of findContent call above.
var embedded embed.FS // 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 { func subdir(fsys fs.FS, path string) fs.FS {
s, err := fs.Sub(fsys, path) s, err := fs.Sub(fsys, path)

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

@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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, // This file caches information about which standard library types, methods,
// and functions appeared in what version of Go // and functions appeared in what version of Go
@ -12,13 +9,14 @@ package api
import ( import (
"bufio" "bufio"
"io/fs"
"path" "path"
"path/filepath" "path/filepath"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"unicode" "unicode"
"golang.org/x/website/internal/backport/io/fs"
) )
// DB is a map of packages to information about those packages' // 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 // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package api package api
import ( import (
"go/build" "go/build"
"os"
"runtime" "runtime"
"testing" "testing"
"golang.org/x/website/internal/backport/osfs"
) )
func TestParseVersionRow(t *testing.T) { func TestParseVersionRow(t *testing.T) {
@ -93,7 +91,7 @@ func hasTag(t string) bool {
} }
func TestAPIVersion(t *testing.T) { func TestAPIVersion(t *testing.T) {
av, err := Load(os.DirFS(runtime.GOROOT())) av, err := Load(osfs.DirFS(runtime.GOROOT()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

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

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

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

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

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

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

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

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

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

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

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

@ -5,7 +5,7 @@
// Package history stores historical data for the Go project. // Package history stores historical data for the Go project.
package history package history
import "html/template" import "golang.org/x/website/internal/backport/html/template"
// Releases summarizes the changes between official stable releases of Go. // 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 // 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 // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // 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. // This file contains the code dealing with package directory trees.
package pkgdoc package pkgdoc
@ -15,11 +12,12 @@ import (
"go/doc" "go/doc"
"go/parser" "go/parser"
"go/token" "go/token"
"io/fs"
"log" "log"
"path" "path"
"sort" "sort"
"strings" "strings"
"golang.org/x/website/internal/backport/io/fs"
) )
type Dir struct { type Dir struct {

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

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

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

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

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

@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package pkgdoc package pkgdoc
import ( import (
"testing" "testing"
"testing/fstest"
"golang.org/x/website/internal/backport/testing/fstest"
) )
// TestIgnoredGoFiles tests the scenario where a folder has no .go or .c files, // 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 ( import (
"context" "context"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
@ -20,6 +19,7 @@ import (
"time" "time"
"golang.org/x/net/context/ctxhttp" "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 // Register registers HTTP handlers that redirect old godoc paths to their new

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

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

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

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

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

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

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

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

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

@ -2,18 +2,16 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build go1.16
// +build go1.16
package web package web
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"io/fs"
"log" "log"
"path" "path"
"strings" "strings"
"golang.org/x/website/internal/backport/io/fs"
) )
type file struct { type file struct {
@ -45,7 +43,9 @@ func open(fsys fs.FS, relpath string) *file {
relpath = strings.TrimSuffix(relpath, "/") 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 filePath string
var b []byte var b []byte
var err error var err error

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

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

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

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

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

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

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

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

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

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

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

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

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

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