Skip to content

Commit

Permalink
Replace use of deprecated io/ioutil
Browse files Browse the repository at this point in the history
All the calls have been converted to their new equivalent.

Signed-off-by: Andrea Barberio <[email protected]>
  • Loading branch information
insomniacslk committed Oct 18, 2023
1 parent 60d5d29 commit db61ab1
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 27 deletions.
6 changes: 3 additions & 3 deletions cmds/coredhcp-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can use `coredhcp-generator` to generate a `main.go` that includes all the
plugins you wish. Just use it as follows:

```
$ ./coredhcp-generator -from core-plugins.txt
$ ./coredhcp-generator --from core-plugins.txt
2019/11/21 23:32:04 Generating output file '/tmp/coredhcp547019106/coredhcp.go' with 7 plugin(s):
2019/11/21 23:32:04 1) github.com/coredhcp/coredhcp/plugins/file
2019/11/21 23:32:04 2) github.com/coredhcp/coredhcp/plugins/lease_time
Expand All @@ -25,9 +25,9 @@ $ ./coredhcp-generator -from core-plugins.txt
```

You can also specify the plugin list on the command line, or mix it with
`-from`:
`--from`:
```
$ ./coredhcp-generator -from core-plugins.txt \
$ ./coredhcp-generator --from core-plugins.txt \
github.com/coredhcp/plugins/redis
```

Expand Down
4 changes: 2 additions & 2 deletions cmds/coredhcp-generator/coredhcp.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package main

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

Expand All @@ -36,7 +36,7 @@ var (
)

var logLevels = map[string]func(*logrus.Logger){
"none": func(l *logrus.Logger) { l.SetOutput(ioutil.Discard) },
"none": func(l *logrus.Logger) { l.SetOutput(io.Discard) },
"debug": func(l *logrus.Logger) { l.SetLevel(logrus.DebugLevel) },
"info": func(l *logrus.Logger) { l.SetLevel(logrus.InfoLevel) },
"warning": func(l *logrus.Logger) { l.SetLevel(logrus.WarnLevel) },
Expand Down
5 changes: 2 additions & 3 deletions cmds/coredhcp-generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"bufio"
"fmt"
"html/template"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -54,7 +53,7 @@ func main() {
flag.Usage = usage
flag.Parse()

data, err := ioutil.ReadFile(*flagTemplate)
data, err := os.ReadFile(*flagTemplate)
if err != nil {
log.Fatalf("Failed to read template file '%s': %v", *flagTemplate, err)
}
Expand Down Expand Up @@ -109,7 +108,7 @@ func main() {
}
outfile := *flagOutfile
if outfile == "" {
tmpdir, err := ioutil.TempDir("", "coredhcp")
tmpdir, err := os.MkdirTemp("", "coredhcp")
if err != nil {
log.Fatalf("Cannot create temporary directory: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmds/coredhcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package main

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

Expand Down Expand Up @@ -44,7 +44,7 @@ var (
)

var logLevels = map[string]func(*logrus.Logger){
"none": func(l *logrus.Logger) { l.SetOutput(ioutil.Discard) },
"none": func(l *logrus.Logger) { l.SetOutput(io.Discard) },
"debug": func(l *logrus.Logger) { l.SetLevel(logrus.DebugLevel) },
"info": func(l *logrus.Logger) { l.SetLevel(logrus.InfoLevel) },
"warning": func(l *logrus.Logger) { l.SetLevel(logrus.WarnLevel) },
Expand Down
4 changes: 2 additions & 2 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package logger

import (
"io/ioutil"
"io"
"sync"

log_prefixed "github.com/chappjc/logrus-prefix"
Expand Down Expand Up @@ -42,5 +42,5 @@ func WithFile(log *logrus.Entry, logfile string) {

// WithNoStdOutErr disables logging to stdout/stderr.
func WithNoStdOutErr(log *logrus.Entry) {
log.Logger.SetOutput(ioutil.Discard)
log.Logger.SetOutput(io.Discard)
}
6 changes: 3 additions & 3 deletions plugins/file/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -75,7 +75,7 @@ var (
// IPv4 address.
func LoadDHCPv4Records(filename string) (map[string]net.IP, error) {
log.Infof("reading leases from %s", filename)
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func LoadDHCPv4Records(filename string) (map[string]net.IP, error) {
// IPv6 address.
func LoadDHCPv6Records(filename string) (map[string]net.IP, error) {
log.Infof("reading leases from %s", filename)
data, err := ioutil.ReadFile(filename)
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
Expand Down
23 changes: 11 additions & 12 deletions plugins/file/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package file

import (
"io/ioutil"
"net"
"os"
"testing"
Expand All @@ -20,7 +19,7 @@ import (
func TestLoadDHCPv4Records(t *testing.T) {
t.Run("valid leases", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand Down Expand Up @@ -52,7 +51,7 @@ func TestLoadDHCPv4Records(t *testing.T) {

t.Run("missing field", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand All @@ -68,7 +67,7 @@ func TestLoadDHCPv4Records(t *testing.T) {

t.Run("invalid MAC", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand All @@ -84,7 +83,7 @@ func TestLoadDHCPv4Records(t *testing.T) {

t.Run("invalid IP address", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand All @@ -100,7 +99,7 @@ func TestLoadDHCPv4Records(t *testing.T) {

t.Run("lease with IPv6 address", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand All @@ -118,7 +117,7 @@ func TestLoadDHCPv4Records(t *testing.T) {
func TestLoadDHCPv6Records(t *testing.T) {
t.Run("valid leases", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand Down Expand Up @@ -150,7 +149,7 @@ func TestLoadDHCPv6Records(t *testing.T) {

t.Run("missing field", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand All @@ -166,7 +165,7 @@ func TestLoadDHCPv6Records(t *testing.T) {

t.Run("invalid MAC", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand All @@ -182,7 +181,7 @@ func TestLoadDHCPv6Records(t *testing.T) {

t.Run("invalid IP address", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand All @@ -198,7 +197,7 @@ func TestLoadDHCPv6Records(t *testing.T) {

t.Run("lease with IPv4 address", func(t *testing.T) {
// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand Down Expand Up @@ -325,7 +324,7 @@ func TestSetupFile(t *testing.T) {
assert.Error(t, err)

// setup temp leases file
tmp, err := ioutil.TempFile("", "test_plugin_file")
tmp, err := os.CreateTemp("", "test_plugin_file")
require.NoError(t, err)
defer func() {
tmp.Close()
Expand Down

0 comments on commit db61ab1

Please sign in to comment.