Skip to content

Commit

Permalink
drop io/ioutil
Browse files Browse the repository at this point in the history
io/ioutil has been deprecated since go1.16.
  • Loading branch information
magiconair committed Jan 13, 2023
1 parent cec7327 commit 08515ab
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
3 changes: 1 addition & 2 deletions cmd/id/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"encoding/csv"
"flag"
"go/format"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -55,7 +54,7 @@ func main() {
log.Fatalf("Error formatting code: %v", err)
}

if err := ioutil.WriteFile(*out, bfmt, 0644); err != nil {
if err := os.WriteFile(*out, bfmt, 0644); err != nil {
log.Fatalf("Error writing %s: %v", *out, err)
}
log.Printf("Wrote %s", *out)
Expand Down
4 changes: 2 additions & 2 deletions cmd/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"strings"
Expand Down Expand Up @@ -80,7 +80,7 @@ func write(src []byte, filename string) {

b.Write(src)

if err := ioutil.WriteFile(filename, b.Bytes(), 0644); err != nil {
if err := os.WriteFile(filename, b.Bytes(), 0644); err != nil {
log.Fatalf("Failed to write %s: %v", filename, err)
}

Expand Down
3 changes: 1 addition & 2 deletions cmd/status/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"flag"
"go/format"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -66,7 +65,7 @@ func main() {
log.Fatalf("Error formatting source: %v", err)
}

if err := ioutil.WriteFile(*out, bfmt, 0644); err != nil {
if err := os.WriteFile(*out, bfmt, 0644); err != nil {
log.Fatalf("Error writing %s: %v", *out, err)
}
log.Printf("Wrote %s", *out)
Expand Down
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"io/ioutil"
"log"
"math/rand"
"net"
"os"
"strings"
"time"

Expand Down Expand Up @@ -247,7 +247,7 @@ func PrivateKeyFile(filename string) Option {
}

func loadPrivateKey(filename string) (*rsa.PrivateKey, error) {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return nil, errors.Errorf("Failed to load private key: %s", err)
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func CertificateFile(filename string) Option {
}

func loadCertificate(filename string) ([]byte, error) {
b, err := ioutil.ReadFile(filename)
b, err := os.ReadFile(filename)
if err != nil {
return nil, errors.Errorf("Failed to load certificate: %s", err)
}
Expand Down
11 changes: 5 additions & 6 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto/tls"
"encoding/pem"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -130,7 +129,7 @@ func TestOptions(t *testing.T) {
randomRequestID = func() uint32 { return 125 }
defer func() { randomRequestID = nil }()

d, err := ioutil.TempDir("", "gopcua")
d, err := os.MkdirTemp("", "gopcua")
if err != nil {
t.Fatal(err)
}
Expand All @@ -153,16 +152,16 @@ func TestOptions(t *testing.T) {
}
}

if err := ioutil.WriteFile(certDERFile, certDER, 0644); err != nil {
if err := os.WriteFile(certDERFile, certDER, 0644); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(certPEMFile, certPEM, 0644); err != nil {
if err := os.WriteFile(certPEMFile, certPEM, 0644); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(keyDERFile, keyDER, 0644); err != nil {
if err := os.WriteFile(keyDERFile, keyDER, 0644); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(keyPEMFile, keyPEM, 0644); err != nil {
if err := os.WriteFile(keyPEMFile, keyPEM, 0644); err != nil {
t.Fatal(err)
}
defer os.Remove(keyPEMFile)
Expand Down
6 changes: 3 additions & 3 deletions debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ package debug
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"strings"
)

// Flags contains the debug flags set by OPC_DEBUG.
//
// * codec : print detailed debugging information when encoding/decoding
// - codec : print detailed debugging information when encoding/decoding
var Flags = os.Getenv("OPC_DEBUG")

// Enable controls whether debug logging is enabled. It is disabled by default.
Expand All @@ -29,7 +29,7 @@ var Logger = log.New(os.Stderr, "debug: ", 0)
// Otherwise, a discarding logger is returned.
func NewPrefixLogger(format string, args ...interface{}) *log.Logger {
if !Enable {
return log.New(ioutil.Discard, "", 0)
return log.New(io.Discard, "", 0)
}
return log.New(os.Stderr, "debug: "+fmt.Sprintf(format, args...), 0)
}
Expand Down

0 comments on commit 08515ab

Please sign in to comment.