Skip to content

Commit

Permalink
Replace ioutil usage with io and os
Browse files Browse the repository at this point in the history
ioutil has been deprecated since Go 1.16 and can be completely replaced
with io and os functions.
  • Loading branch information
ctlong committed Jan 9, 2023
1 parent 5da42db commit 2a66beb
Show file tree
Hide file tree
Showing 27 changed files with 69 additions and 85 deletions.
13 changes: 6 additions & 7 deletions apps/admin_buildpack_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apps

import (
"fmt"
"io/ioutil"
"os"
"path"

Expand Down Expand Up @@ -69,12 +68,12 @@ var _ = AppsDescribe("Admin Buildpacks", func() {
appName = CATSRandomName("APP")
appNames = append(appNames, appName)

tmpdir, err := ioutil.TempDir(os.TempDir(), "matching-app")
tmpdir, err := os.MkdirTemp(os.TempDir(), "matching-app")
Expect(err).ToNot(HaveOccurred())

appPath = tmpdir

tmpdir, err = ioutil.TempDir(os.TempDir(), "matching-buildpack")
tmpdir, err = os.MkdirTemp(os.TempDir(), "matching-buildpack")
Expect(err).ToNot(HaveOccurred())

buildpackPath = tmpdir
Expand Down Expand Up @@ -140,12 +139,12 @@ EOF
appName = CATSRandomName("APP")
appNames = append(appNames, appName)

tmpdir, err := ioutil.TempDir(os.TempDir(), "matching-app")
tmpdir, err := os.MkdirTemp(os.TempDir(), "matching-app")
Expect(err).ToNot(HaveOccurred())

appPath = tmpdir

tmpdir, err = ioutil.TempDir(os.TempDir(), "matching-buildpack")
tmpdir, err = os.MkdirTemp(os.TempDir(), "matching-buildpack")
Expect(err).ToNot(HaveOccurred())

buildpackPath = tmpdir
Expand Down Expand Up @@ -211,12 +210,12 @@ EOF
appName = CATSRandomName("APP")
appNames = append(appNames, appName)

tmpdir, err := ioutil.TempDir(os.TempDir(), "matching-app")
tmpdir, err := os.MkdirTemp(os.TempDir(), "matching-app")
Expect(err).ToNot(HaveOccurred())

appPath = tmpdir

tmpdir, err = ioutil.TempDir(os.TempDir(), "matching-buildpack")
tmpdir, err = os.MkdirTemp(os.TempDir(), "matching-buildpack")
Expect(err).ToNot(HaveOccurred())

buildpackPath = tmpdir
Expand Down
7 changes: 3 additions & 4 deletions apps/app_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apps

import (
"fmt"
"io/ioutil"
"os"
"path"

Expand Down Expand Up @@ -46,12 +45,12 @@ var _ = AppsDescribe("Specifying a specific stack", func() {
appName = CATSRandomName("APP")

var err error
tmpdir, err = ioutil.TempDir("", "stack")
tmpdir, err = os.MkdirTemp("", "stack")
Expect(err).ToNot(HaveOccurred())
appPath, err = ioutil.TempDir(tmpdir, "matching-app")
appPath, err = os.MkdirTemp(tmpdir, "matching-app")
Expect(err).ToNot(HaveOccurred())

buildpackPath, err = ioutil.TempDir(tmpdir, "matching-buildpack")
buildpackPath, err = os.MkdirTemp(tmpdir, "matching-buildpack")
Expect(err).ToNot(HaveOccurred())

buildpackArchivePath = path.Join(buildpackPath, "buildpack.zip")
Expand Down
7 changes: 3 additions & 4 deletions apps/app_staging_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apps

import (
"fmt"
"io/ioutil"
"os"
"path"

Expand Down Expand Up @@ -44,12 +43,12 @@ var _ = AppsDescribe("Buildpack Environment", func() {
appName = CATSRandomName("APP")

var err error
tmpdir, err = ioutil.TempDir("", "buildpack_env")
tmpdir, err = os.MkdirTemp("", "buildpack_env")
Expect(err).ToNot(HaveOccurred())
appPath, err = ioutil.TempDir(tmpdir, "matching-app")
appPath, err = os.MkdirTemp(tmpdir, "matching-app")
Expect(err).ToNot(HaveOccurred())

buildpackPath, err = ioutil.TempDir(tmpdir, "matching-buildpack")
buildpackPath, err = os.MkdirTemp(tmpdir, "matching-buildpack")
Expect(err).ToNot(HaveOccurred())

buildpackArchivePath = path.Join(buildpackPath, "buildpack.zip")
Expand Down
5 changes: 2 additions & 3 deletions apps/buildpack_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package apps

import (
"fmt"
"io/ioutil"
"os"
"path"
"time"
Expand Down Expand Up @@ -43,12 +42,12 @@ var _ = AppsDescribe("Buildpack cache", func() {
BuildpackName = CATSRandomName("BPK")
appName = CATSRandomName("APP")

tmpdir, err := ioutil.TempDir(os.TempDir(), "matching-app")
tmpdir, err := os.MkdirTemp(os.TempDir(), "matching-app")
Expect(err).ToNot(HaveOccurred())

appPath = tmpdir

tmpdir, err = ioutil.TempDir(os.TempDir(), "matching-buildpack")
tmpdir, err = os.MkdirTemp(os.TempDir(), "matching-buildpack")
Expect(err).ToNot(HaveOccurred())

buildpackPath = tmpdir
Expand Down
4 changes: 2 additions & 2 deletions apps/default_environment_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package apps

import (
"encoding/json"
"io/ioutil"
"os"
"path"
"strings"

Expand All @@ -25,7 +25,7 @@ import (

var _ = AppsDescribe("Default Environment Variables", func() {
var createBuildpack = func() string {
tmpPath, err := ioutil.TempDir("", "default-env-var-test")
tmpPath, err := os.MkdirTemp("", "default-env-var-test")
Expect(err).ToNot(HaveOccurred())

buildpackArchivePath := path.Join(tmpPath, "buildpack.zip")
Expand Down
3 changes: 1 addition & 2 deletions apps/droplet_uploading_and_downloading.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package apps

import (
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -29,7 +28,7 @@ func appGuid(appName string) string {

func makeTempDir() string {
// This defers from the typical way temp directories are created (using the OS default), because the GNUWin32 tar.exe does not allow file paths to be prefixed with a drive letter.
tmpdir, err := ioutil.TempDir(".", "droplet-download")
tmpdir, err := os.MkdirTemp(".", "droplet-download")
Expect(err).ToNot(HaveOccurred())
return tmpdir
}
Expand Down
4 changes: 2 additions & 2 deletions apps/environment_variables_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package apps
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
"time"
Expand Down Expand Up @@ -32,7 +32,7 @@ var _ = AppsDescribe("Environment Variables Groups", func() {
}

var createBuildpack = func(envVarName string) string {
tmpPath, err := ioutil.TempDir("", "env-group-staging")
tmpPath, err := os.MkdirTemp("", "env-group-staging")
Expect(err).ToNot(HaveOccurred())

buildpackArchivePath := path.Join(tmpPath, "buildpack.zip")
Expand Down
10 changes: 5 additions & 5 deletions assets/logging-route-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"bytes"
"crypto/tls"
"io/ioutil"
"io"
"log"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -43,11 +43,11 @@ func NewProxy(transport http.RoundTripper, skipSslValidation bool) http.Handler
var body []byte
var err error
if req.Body != nil {
body, err = ioutil.ReadAll(req.Body)
body, err = io.ReadAll(req.Body)
if err != nil {
log.Fatalln(err.Error())
}
req.Body = ioutil.NopCloser(bytes.NewBuffer(body))
req.Body = io.NopCloser(bytes.NewBuffer(body))
}
logRequest(forwardedURL, sigHeader, string(body), req.Header, skipSslValidation)

Expand Down Expand Up @@ -104,7 +104,7 @@ func (lrt *LoggingRoundTripper) RoundTrip(request *http.Request) (*http.Response
return nil, err
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
log.Fatalln(err.Error())
}
Expand All @@ -113,7 +113,7 @@ func (lrt *LoggingRoundTripper) RoundTrip(request *http.Request) (*http.Response
log.Println("")
log.Printf("Response Body: %s\n", string(body))
log.Println("")
res.Body = ioutil.NopCloser(bytes.NewBuffer(body))
res.Body = io.NopCloser(bytes.NewBuffer(body))

log.Println("Sending response to GoRouter...")

Expand Down
19 changes: 9 additions & 10 deletions assets/pora/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -79,13 +78,13 @@ func write(res http.ResponseWriter, req *http.Request) {
mountPointPath := getPath() + "/poratest-" + randomString(10)

d1 := []byte("Hello Persistent World!\n")
err := ioutil.WriteFile(mountPointPath, d1, 0644)
err := os.WriteFile(mountPointPath, d1, 0644)
if err != nil {
writeError(res, "Writing \n", err)
return
}

body, err := ioutil.ReadFile(mountPointPath)
body, err := os.ReadFile(mountPointPath)
if err != nil {
writeError(res, "Reading \n", err)
return
Expand All @@ -107,7 +106,7 @@ func dataLoad(res http.ResponseWriter, req *http.Request) {
mountPointPath := getPath() + "/poraload-" + randomString(10)

d1 := []byte("Hello Persistent World!\n")
err := ioutil.WriteFile(mountPointPath, d1, 0644)
err := os.WriteFile(mountPointPath, d1, 0644)
if err != nil {
writeError(res, "Writing \n", err)
return
Expand All @@ -116,12 +115,12 @@ func dataLoad(res http.ResponseWriter, req *http.Request) {
var totalIO int
for startTime := time.Now(); time.Since(startTime) < 4*time.Second; {
d2 := []byte(randomString(1048576))
err := ioutil.WriteFile(mountPointPath, d2, 0644)
err := os.WriteFile(mountPointPath, d2, 0644)
if err != nil {
writeError(res, "Writing Load\n", err)
return
}
body, err := ioutil.ReadFile(mountPointPath)
body, err := os.ReadFile(mountPointPath)
if err != nil {
writeError(res, "Reading Load\n", err)
return
Expand Down Expand Up @@ -159,13 +158,13 @@ func backgroundLoad() {
filePath := filepath.Join(dirPath, "poraload-"+os.Getenv("INSTANCE_INDEX"))

d2 := []byte(randomString(1048576))
err := ioutil.WriteFile(filePath, d2, 0644)
err := os.WriteFile(filePath, d2, 0644)
if err != nil {
fmt.Println(err)
return
}

body, err := ioutil.ReadFile(filePath)
body, err := os.ReadFile(filePath)
if err != nil {
fmt.Println(err)
return
Expand Down Expand Up @@ -207,7 +206,7 @@ func createFile(res http.ResponseWriter, _ *http.Request) {
mountPointPath := filepath.Join(getPath(), fileName)

d1 := []byte("Hello Persistent World!\n")
err := ioutil.WriteFile(mountPointPath, d1, 0644)
err := os.WriteFile(mountPointPath, d1, 0644)
if err != nil {
writeError(res, "Writing \n", err)
return
Expand Down Expand Up @@ -236,7 +235,7 @@ func readFile(res http.ResponseWriter, req *http.Request) {
fileName := parts[len(parts)-1]
mountPointPath := filepath.Join(getPath(), fileName)

body, err := ioutil.ReadFile(mountPointPath)
body, err := os.ReadFile(mountPointPath)
if err != nil {
res.WriteHeader(http.StatusNotFound)
res.Write([]byte(err.Error()))
Expand Down
4 changes: 2 additions & 2 deletions assets/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -77,7 +77,7 @@ func handleRequest(destination string, resp http.ResponseWriter, req *http.Reque
}
defer getResp.Body.Close()

readBytes, err := ioutil.ReadAll(getResp.Body)
readBytes, err := io.ReadAll(getResp.Body)
if err != nil {
resp.WriteHeader(http.StatusInternalServerError)
_, _ = resp.Write([]byte(fmt.Sprintf("read body failed: %s", err)))
Expand Down
3 changes: 1 addition & 2 deletions cats_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cats_test

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -89,7 +88,7 @@ func TestCATS(t *testing.T) {
err = buildCmd.Run()
Expect(err).NotTo(HaveOccurred())

doraFiles, err := ioutil.ReadDir(assets.NewAssets().Dora)
doraFiles, err := os.ReadDir(assets.NewAssets().Dora)
Expect(err).NotTo(HaveOccurred())

var doraFileNames []string
Expand Down
7 changes: 3 additions & 4 deletions credhub/service_bindings.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package credhub

import (
"io/ioutil"
"os"
"path"
"time"
Expand Down Expand Up @@ -146,12 +145,12 @@ var _ = CredhubDescribe("service bindings", func() {
appName = random_name.CATSRandomName("APP")

var err error
tmpdir, err = ioutil.TempDir("", "buildpack_env")
tmpdir, err = os.MkdirTemp("", "buildpack_env")
Expect(err).ToNot(HaveOccurred())
appPath, err = ioutil.TempDir(tmpdir, "matching-app")
appPath, err = os.MkdirTemp(tmpdir, "matching-app")
Expect(err).ToNot(HaveOccurred())

buildpackPath, err = ioutil.TempDir(tmpdir, "matching-buildpack")
buildpackPath, err = os.MkdirTemp(tmpdir, "matching-buildpack")
Expect(err).ToNot(HaveOccurred())

buildpackArchivePath = path.Join(buildpackPath, "buildpack.zip")
Expand Down
6 changes: 3 additions & 3 deletions helpers/app_helpers/app_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package app_helpers

import (
"fmt"
"io/ioutil"
"os"
"strings"
"time"

Expand Down Expand Up @@ -30,7 +30,7 @@ func CatnipWithArgs(appName string, args ...string) []string {
}

if Config.RunningOnK8s() {
ioutil.WriteFile("assets/catnip/bin/Procfile", []byte("web: ./catnip"), 0644)
os.WriteFile("assets/catnip/bin/Procfile", []byte("web: ./catnip"), 0644)
}

pushArgs = append(pushArgs, args...)
Expand All @@ -51,7 +51,7 @@ func BinaryWithArgs(appName string, args ...string) []string {
}

if Config.RunningOnK8s() {
ioutil.WriteFile("assets/binary/bin/Procfile", []byte("web: ./app"), 0644)
os.WriteFile("assets/binary/bin/Procfile", []byte("web: ./app"), 0644)
}

pushArgs = append(pushArgs, args...)
Expand Down
Loading

0 comments on commit 2a66beb

Please sign in to comment.