Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil (jpillora#459)
Browse files Browse the repository at this point in the history
thanks @testwill
  • Loading branch information
testwill authored and NewtonMan committed Oct 16, 2024
1 parent 51a8acf commit f27813f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 26 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -118,7 +118,7 @@ func NewClient(c *Config) (*Client, error) {
tc.InsecureSkipVerify = true
} else if c.TLS.CA != "" {
rootCAs := x509.NewCertPool()
if b, err := ioutil.ReadFile(c.TLS.CA); err != nil {
if b, err := os.ReadFile(c.TLS.CA); err != nil {
return nil, fmt.Errorf("Failed to load file: %s", c.TLS.CA)
} else if ok := rootCAs.AppendCertsFromPEM(b); !ok {
return nil, fmt.Errorf("Failed to decode PEM: %s", c.TLS.CA)
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -89,7 +88,7 @@ var commonHelp = `

func generatePidFile() {
pid := []byte(strconv.Itoa(os.Getpid()))
if err := ioutil.WriteFile("chisel.pid", pid, 0644); err != nil {
if err := os.WriteFile("chisel.pid", pid, 0644); err != nil {
log.Fatal(err)
}
}
Expand Down
5 changes: 2 additions & 3 deletions server/server_listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/tls"
"crypto/x509"
"errors"
"io/ioutil"
"net"
"os"
"os/user"
Expand Down Expand Up @@ -116,7 +115,7 @@ func addCA(ca string, c *tls.Config) error {
clientCAPool := x509.NewCertPool()
if fileInfo.IsDir() {
//this is a directory holding CA bundle files
files, err := ioutil.ReadDir(ca)
files, err := os.ReadDir(ca)
if err != nil {
return err
}
Expand All @@ -140,7 +139,7 @@ func addCA(ca string, c *tls.Config) error {
}

func addPEMFile(path string, pool *x509.CertPool) error {
content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions share/cio/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cio

import (
"io"
"io/ioutil"
"os"
)

Expand All @@ -11,6 +10,6 @@ var Stdio = &struct {
io.ReadCloser
io.Writer
}{
ioutil.NopCloser(os.Stdin),
io.NopCloser(os.Stdin),
os.Stdout,
}
4 changes: 2 additions & 2 deletions share/settings/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"regexp"
"sync"

Expand Down Expand Up @@ -125,7 +125,7 @@ func (u *UserIndex) loadUserIndex() error {
if u.configFile == "" {
return errors.New("configuration file not set")
}
b, err := ioutil.ReadFile(u.configFile)
b, err := os.ReadFile(u.configFile)
if err != nil {
return fmt.Errorf("Failed to read auth file: %s, error: %s", u.configFile, err)
}
Expand Down
4 changes: 2 additions & 2 deletions share/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"io"
"log"
"os"
"sync"
Expand Down Expand Up @@ -57,7 +57,7 @@ func New(c Config) *Tunnel {
//setup socks server (not listening on any port!)
extra := ""
if c.Socks {
sl := log.New(ioutil.Discard, "", 0)
sl := log.New(io.Discard, "", 0)
if t.Logger.Debug {
sl = log.New(os.Stdout, "[socks]", log.Ldate|log.Ltime)
}
Expand Down
3 changes: 1 addition & 2 deletions test/bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -86,7 +85,7 @@ func testTunnel(port string, size int) {
fatal(err)
}

n, err := io.Copy(ioutil.Discard, resp.Body)
n, err := io.Copy(io.Discard, resp.Body)
if err != nil {
fatal(err)
}
Expand Down
15 changes: 7 additions & 8 deletions test/e2e/cert_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"io/ioutil"
"math/big"
"net"
"os"
Expand Down Expand Up @@ -53,7 +52,7 @@ func newTestTLSConfig() (*tlsConfig, error) {
return nil, err
}

tlsConfig.tmpDir, err = ioutil.TempDir("", "")
tlsConfig.tmpDir, err = os.MkdirTemp("", "")
if err != nil {
return nil, err
}
Expand All @@ -63,7 +62,7 @@ func newTestTLSConfig() (*tlsConfig, error) {
return nil, err
}
pathServerCACrt := path.Join(dirServerCA, "client.crt")
if err := ioutil.WriteFile(pathServerCACrt, clientCertPEM, 0666); err != nil {
if err := os.WriteFile(pathServerCACrt, clientCertPEM, 0666); err != nil {
return nil, err
}

Expand All @@ -72,7 +71,7 @@ func newTestTLSConfig() (*tlsConfig, error) {
return nil, err
}
pathClientCACrt := path.Join(dirClientCA, "server.crt")
if err := ioutil.WriteFile(pathClientCACrt, serverCertPEM, 0666); err != nil {
if err := os.WriteFile(pathClientCACrt, serverCertPEM, 0666); err != nil {
return nil, err
}

Expand All @@ -81,11 +80,11 @@ func newTestTLSConfig() (*tlsConfig, error) {
return nil, err
}
pathServerCrtCrt := path.Join(dirServerCrt, "server.crt")
if err := ioutil.WriteFile(pathServerCrtCrt, serverCertPEM, 0666); err != nil {
if err := os.WriteFile(pathServerCrtCrt, serverCertPEM, 0666); err != nil {
return nil, err
}
pathServerCrtKey := path.Join(dirServerCrt, "server.key")
if err := ioutil.WriteFile(pathServerCrtKey, serverKeyPEM, 0666); err != nil {
if err := os.WriteFile(pathServerCrtKey, serverKeyPEM, 0666); err != nil {
return nil, err
}

Expand All @@ -94,11 +93,11 @@ func newTestTLSConfig() (*tlsConfig, error) {
return nil, err
}
pathClientCrtCrt := path.Join(dirClientCrt, "client.crt")
if err := ioutil.WriteFile(pathClientCrtCrt, clientCertPEM, 0666); err != nil {
if err := os.WriteFile(pathClientCrtCrt, clientCertPEM, 0666); err != nil {
return nil, err
}
pathClientCrtKey := path.Join(dirClientCrt, "client.key")
if err := ioutil.WriteFile(pathClientCrtKey, clientKeyPEM, 0666); err != nil {
if err := os.WriteFile(pathClientCrtKey, clientKeyPEM, 0666); err != nil {
return nil, err
}

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package e2e_test

import (
"context"
"io/ioutil"
"io"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -36,7 +36,7 @@ func (tl *testLayout) setup(t *testing.T) (server *chserver.Server, client *chcl
fileAddr := "127.0.0.1:" + filePort
f := http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, _ := ioutil.ReadAll(r.Body)
b, _ := io.ReadAll(r.Body)
w.Write(append(b, '!'))
}),
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func post(url, body string) (string, error) {
if err != nil {
return "", err
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down

0 comments on commit f27813f

Please sign in to comment.