all: replace io/ioutil with io and os package

Change-Id: I84f4996a1eaae239a5152866aa34033847da38bc
GitHub-Last-Rev: 60cc9c27b5d8fa12ff52faed815518c89a5bdb0d
GitHub-Pull-Request: golang/playground#19
Reviewed-on: https://go-review.googlesource.com/c/playground/+/430595
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
diff --git a/client.go b/client.go
index dc7ead8..c49c121 100644
--- a/client.go
+++ b/client.go
@@ -9,13 +9,13 @@
 
 import (
 	"encoding/json"
-	"io/ioutil"
+	"io"
 	"log"
 	"os"
 )
 
 func main() {
-	body, err := ioutil.ReadAll(os.Stdin)
+	body, err := io.ReadAll(os.Stdin)
 	if err != nil {
 		log.Fatalf("error reading stdin: %v", err)
 	}
diff --git a/internal/gcpdial/gcpdial.go b/internal/gcpdial/gcpdial.go
index 9fe3661..c9d4dce 100644
--- a/internal/gcpdial/gcpdial.go
+++ b/internal/gcpdial/gcpdial.go
@@ -10,7 +10,6 @@
 	"context"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"log"
 	"math/rand"
 	"net/http"
@@ -91,7 +90,7 @@
 	res, err := http.DefaultClient.Do(req)
 	if res != nil {
 		defer res.Body.Close()
-		defer io.Copy(ioutil.Discard, res.Body)
+		defer io.Copy(io.Discard, res.Body)
 	}
 	healthy := err == nil && res.StatusCode == http.StatusOK
 	if healthy == p.healthy {
diff --git a/sandbox.go b/sandbox.go
index b7864be..47f3b06 100644
--- a/sandbox.go
+++ b/sandbox.go
@@ -19,7 +19,6 @@
 	"go/parser"
 	"go/token"
 	"io"
-	"io/ioutil"
 	"net"
 	"net/http"
 	"os"
@@ -331,7 +330,7 @@
 // *response.Errors contains an explanation for a user.
 func compileAndRun(ctx context.Context, req *request) (*response, error) {
 	// TODO(andybons): Add semaphore to limit number of running programs at once.
-	tmpDir, err := ioutil.TempDir("", "sandbox")
+	tmpDir, err := os.MkdirTemp("", "sandbox")
 	if err != nil {
 		return nil, fmt.Errorf("error creating temp directory: %v", err)
 	}
@@ -457,7 +456,7 @@
 				return nil, err
 			}
 		}
-		if err := ioutil.WriteFile(in, src, 0644); err != nil {
+		if err := os.WriteFile(in, src, 0644); err != nil {
 			return nil, fmt.Errorf("error creating temp file %q: %v", in, err)
 		}
 	}
@@ -474,7 +473,7 @@
 	// into GOPATH/pkg/mod.
 	cmd.Args = append(cmd.Args, "-modcacherw")
 	cmd.Args = append(cmd.Args, "-mod=mod")
-	br.goPath, err = ioutil.TempDir("", "gopath")
+	br.goPath, err = os.MkdirTemp("", "gopath")
 	if err != nil {
 		log.Printf("error creating temp directory: %v", err)
 		return nil, fmt.Errorf("error creating temp directory: %v", err)
@@ -537,7 +536,7 @@
 		stats.RecordWithTags(ctx, []tag.Mutator{tag.Upsert(kGoBuildSuccess, status)},
 			mGoRunLatency.M(float64(time.Since(start))/float64(time.Millisecond)))
 	}()
-	exeBytes, err := ioutil.ReadFile(exePath)
+	exeBytes, err := os.ReadFile(exePath)
 	if err != nil {
 		return execRes, err
 	}
@@ -551,7 +550,7 @@
 	if testParam != "" {
 		sreq.Header.Add("X-Argument", testParam)
 	}
-	sreq.GetBody = func() (io.ReadCloser, error) { return ioutil.NopCloser(bytes.NewReader(exeBytes)), nil }
+	sreq.GetBody = func() (io.ReadCloser, error) { return io.NopCloser(bytes.NewReader(exeBytes)), nil }
 	res, err := sandboxBackendClient().Do(sreq)
 	if err != nil {
 		if errors.Is(ctx.Err(), context.DeadlineExceeded) {
@@ -586,7 +585,7 @@
 // healthCheck attempts to build a binary from the source in healthProg.
 // It returns any error returned from sandboxBuild, or nil if none is returned.
 func (s *server) healthCheck(ctx context.Context) error {
-	tmpDir, err := ioutil.TempDir("", "sandbox")
+	tmpDir, err := os.MkdirTemp("", "sandbox")
 	if err != nil {
 		return fmt.Errorf("error creating temp directory: %v", err)
 	}
diff --git a/sandbox/sandbox.go b/sandbox/sandbox.go
index f65e642..45fca98 100644
--- a/sandbox/sandbox.go
+++ b/sandbox/sandbox.go
@@ -20,7 +20,6 @@
 	"flag"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"log"
 	"net/http"
 	"os"
@@ -325,7 +324,7 @@
 	if _, err := io.WriteString(os.Stdout, containedStartMessage); err != nil {
 		log.Fatalf("writing to stdout: %v", err)
 	}
-	slurp, err := ioutil.ReadAll(os.Stdin)
+	slurp, err := io.ReadAll(os.Stdin)
 	if err != nil {
 		log.Fatalf("reading stdin in contained mode: %v", err)
 	}
@@ -335,7 +334,7 @@
 	}
 	metaJSON, bin := slurp[:nl], slurp[nl+1:]
 
-	if err := ioutil.WriteFile(binPath, bin, 0755); err != nil {
+	if err := os.WriteFile(binPath, bin, 0755); err != nil {
 		log.Fatalf("writing contained binary: %v", err)
 	}
 	defer os.Remove(binPath) // not that it matters much, this container will be nuked
@@ -553,7 +552,7 @@
 	}
 	defer func() { <-runSem }()
 
-	bin, err := ioutil.ReadAll(http.MaxBytesReader(w, r.Body, maxBinarySize))
+	bin, err := io.ReadAll(http.MaxBytesReader(w, r.Body, maxBinarySize))
 	if err != nil {
 		log.Printf("failed to read request body: %v", err)
 		http.Error(w, err.Error(), http.StatusInternalServerError)
diff --git a/server_test.go b/server_test.go
index 10e8df2..b1a73a3 100644
--- a/server_test.go
+++ b/server_test.go
@@ -9,7 +9,7 @@
 	"context"
 	"encoding/json"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"net/http"
 	"net/http/httptest"
 	"os"
@@ -97,9 +97,9 @@
 		}
 		if tc.respBody != nil {
 			defer resp.Body.Close()
-			b, err := ioutil.ReadAll(resp.Body)
+			b, err := io.ReadAll(resp.Body)
 			if err != nil {
-				t.Errorf("%s: ioutil.ReadAll(resp.Body): %v", tc.desc, err)
+				t.Errorf("%s: io.ReadAll(resp.Body): %v", tc.desc, err)
 			}
 			if !bytes.Equal(b, tc.respBody) {
 				t.Errorf("%s: got unexpected body %q; want %q", tc.desc, b, tc.respBody)
@@ -152,9 +152,9 @@
 		}
 		if tc.respBody != nil {
 			defer resp.Body.Close()
-			b, err := ioutil.ReadAll(resp.Body)
+			b, err := io.ReadAll(resp.Body)
 			if err != nil {
-				t.Errorf("%s: ioutil.ReadAll(resp.Body): %v", tc.desc, err)
+				t.Errorf("%s: io.ReadAll(resp.Body): %v", tc.desc, err)
 			}
 			if !bytes.Contains(b, tc.respBody) {
 				t.Errorf("%s: got unexpected body %q; want contains %q", tc.desc, b, tc.respBody)
@@ -292,9 +292,9 @@
 			}
 			if tc.respBody != nil {
 				defer resp.Body.Close()
-				b, err := ioutil.ReadAll(resp.Body)
+				b, err := io.ReadAll(resp.Body)
 				if err != nil {
-					t.Errorf("%s: ioutil.ReadAll(resp.Body): %v", tc.desc, err)
+					t.Errorf("%s: io.ReadAll(resp.Body): %v", tc.desc, err)
 				}
 				if !bytes.Equal(b, tc.respBody) {
 					t.Errorf("%s: got unexpected body %q; want %q", tc.desc, b, tc.respBody)
diff --git a/vet.go b/vet.go
index 889c63e..ece62a7 100644
--- a/vet.go
+++ b/vet.go
@@ -7,7 +7,6 @@
 import (
 	"context"
 	"fmt"
-	"io/ioutil"
 	"os"
 	"os/exec"
 	"path/filepath"
@@ -27,14 +26,14 @@
 // boolean set. This code path doesn't support modules and only exists
 // as a temporary compatibility bridge to older javascript clients.
 func vetCheck(ctx context.Context, req *request) (*response, error) {
-	tmpDir, err := ioutil.TempDir("", "vet")
+	tmpDir, err := os.MkdirTemp("", "vet")
 	if err != nil {
 		return nil, fmt.Errorf("error creating temp directory: %v", err)
 	}
 	defer os.RemoveAll(tmpDir)
 
 	in := filepath.Join(tmpDir, progName)
-	if err := ioutil.WriteFile(in, []byte(req.Body), 0400); err != nil {
+	if err := os.WriteFile(in, []byte(req.Body), 0400); err != nil {
 		return nil, fmt.Errorf("error creating temp file %q: %v", in, err)
 	}
 	vetOutput, err := vetCheckInDir(ctx, tmpDir, os.Getenv("GOPATH"))