Skip to content

Commit

Permalink
Stop using deprecated ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
geofffranks authored and ebroberson committed Mar 4, 2024
1 parent a030026 commit d671c0f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package config
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"
"strconv"
"time"

Expand Down Expand Up @@ -132,7 +132,7 @@ type Route struct {
func NewConfigSchemaFromFile(configFile string) (ConfigSchema, error) {
var config ConfigSchema

c, err := ioutil.ReadFile(configFile)
c, err := os.ReadFile(configFile)
if err != nil {
return ConfigSchema{}, err
}
Expand Down
3 changes: 1 addition & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config_test

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

Expand Down Expand Up @@ -153,7 +152,7 @@ var _ = Describe("Config", func() {

BeforeEach(func() {
var err error
configFile, err = ioutil.TempFile("", "route-registrar-config")
configFile, err = os.CreateTemp("", "route-registrar-config")
Expect(err).NotTo(HaveOccurred())

_, err = configFile.Write([]byte("invalid %^&#"))
Expand Down
3 changes: 1 addition & 2 deletions healthchecker/script_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package healthchecker_test
import (
"bytes"
"errors"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -32,7 +31,7 @@ var _ = Describe("ScriptHealthChecker", func() {

BeforeEach(func() {
var err error
tmpDir, err = ioutil.TempDir(os.TempDir(), "healthchecker-test")
tmpDir, err = os.MkdirTemp(os.TempDir(), "healthchecker-test")
Expect(err).ToNot(HaveOccurred())

scriptPath = filepath.Join(tmpDir, "healthchecker.sh")
Expand Down
6 changes: 3 additions & 3 deletions integration/init_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package integration

import (
"code.cloudfoundry.org/routing-api/test_helpers"
"io/ioutil"
"os"
"path/filepath"

"code.cloudfoundry.org/routing-api/test_helpers"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -39,7 +39,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {
}, func(data []byte) {
routeRegistrarBinPath = string(data)

tempDir, err := ioutil.TempDir(os.TempDir(), "route-registrar")
tempDir, err := os.MkdirTemp(os.TempDir(), "route-registrar")
Expect(err).ToNot(HaveOccurred())

pidFile = filepath.Join(tempDir, "route-registrar.pid")
Expand Down
3 changes: 1 addition & 2 deletions integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package integration
import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -105,7 +104,7 @@ var _ = Describe("Main", func() {
session.Kill().Wait()
Eventually(session).Should(gexec.Exit())

pidFileContents, err := ioutil.ReadFile(pidFile)
pidFileContents, err := os.ReadFile(pidFile)
Expect(err).ShouldNot(HaveOccurred())

Expect(len(pidFileContents)).To(BeNumerically(">", 0))
Expand Down
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/x509"
"errors"
"flag"
"io/ioutil"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -67,7 +66,7 @@ func main() {

tlsConfig := &tls.Config{InsecureSkipVerify: c.RoutingAPI.SkipSSLValidation}
if c.RoutingAPI.CACerts != "" {
certBytes, err := ioutil.ReadFile(c.RoutingAPI.CACerts)
certBytes, err := os.ReadFile(c.RoutingAPI.CACerts)
if err != nil {
log.Fatalf("Failed to read ca cert file: %s", err.Error())
}
Expand Down Expand Up @@ -125,7 +124,7 @@ func main() {

if *pidfile != "" {
pid := strconv.Itoa(os.Getpid())
err := ioutil.WriteFile(*pidfile, []byte(pid), 0644)
err := os.WriteFile(*pidfile, []byte(pid), 0644)
logger.Info("Writing pid", lager.Data{"pid": pid, "file": *pidfile})
if err != nil {
logger.Fatal(
Expand Down

0 comments on commit d671c0f

Please sign in to comment.