Skip to content

Commit

Permalink
Merge pull request #733 from Icinga/deprecated-ioutil
Browse files Browse the repository at this point in the history
Remove deprecated io/ioutil package references
  • Loading branch information
julianbrost authored Apr 9, 2024
2 parents d91dc1e + f39c1fb commit fd4ffda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/goccy/go-yaml"
"github.com/jessevdk/go-flags"
"github.com/pkg/errors"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -118,7 +117,7 @@ func (t *TLS) MakeConfig(serverName string) (*tls.Config, error) {
if t.Insecure {
tlsConfig.InsecureSkipVerify = true
} else if t.Ca != "" {
raw, err := ioutil.ReadFile(t.Ca)
raw, err := os.ReadFile(t.Ca)
if err != nil {
return nil, errors.Wrap(err, "can't read CA file")
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/icingadb/objectpacker/objectpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"github.com/pkg/errors"
"io"
"io/ioutil"
"reflect"
"sort"
)
Expand Down Expand Up @@ -102,7 +101,7 @@ func packValue(in reflect.Value, out io.Writer) error {
// If there aren't any values to pack, ...
if l < 1 {
// ... create one and pack it - panics on disallowed type.
_ = packValue(reflect.Zero(in.Type().Elem()), ioutil.Discard)
_ = packValue(reflect.Zero(in.Type().Elem()), io.Discard)
}

return nil
Expand Down Expand Up @@ -140,13 +139,13 @@ func packValue(in reflect.Value, out io.Writer) error {
packedKey = key.Slice(0, key.Len()).Interface().([]byte)
} else {
// Not just stringify the key (below), but also pack it (here) - panics on disallowed type.
_ = packValue(iter.Key(), ioutil.Discard)
_ = packValue(iter.Key(), io.Discard)

packedKey = []byte(fmt.Sprint(key.Interface()))
}
} else {
// Not just stringify the key (below), but also pack it (here) - panics on disallowed type.
_ = packValue(iter.Key(), ioutil.Discard)
_ = packValue(iter.Key(), io.Discard)

packedKey = []byte(fmt.Sprint(key.Interface()))
}
Expand Down Expand Up @@ -176,8 +175,8 @@ func packValue(in reflect.Value, out io.Writer) error {
typ := in.Type()

// ... create one and pack it - panics on disallowed type.
_ = packValue(reflect.Zero(typ.Key()), ioutil.Discard)
_ = packValue(reflect.Zero(typ.Elem()), ioutil.Discard)
_ = packValue(reflect.Zero(typ.Key()), io.Discard)
_ = packValue(reflect.Zero(typ.Elem()), io.Discard)
}

return nil
Expand All @@ -186,7 +185,7 @@ func packValue(in reflect.Value, out io.Writer) error {
err := packValue(reflect.Value{}, out)

// Create a fictive referenced value and pack it - panics on disallowed type.
_ = packValue(reflect.Zero(in.Type().Elem()), ioutil.Discard)
_ = packValue(reflect.Zero(in.Type().Elem()), io.Discard)

return err
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"io/ioutil"
"io"
"math"
"net/http"
"sort"
Expand Down Expand Up @@ -717,7 +717,7 @@ func processCheckResult(t *testing.T, client *utils.Icinga2Client, hostname stri
response, err := client.PostJson("/v1/actions/process-check-result", bytes.NewBuffer(reqBody))
require.NoError(t, err, "process-check-result")
if !assert.Equal(t, 200, response.StatusCode, "process-check-result") {
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
require.NoError(t, err, "reading process-check-result response")
it.Logger(t).Error("process-check-result", zap.ByteString("api-response", body))
t.FailNow()
Expand Down

0 comments on commit fd4ffda

Please sign in to comment.