diff --git a/config/example_config_test.go b/config/example_config_test.go index a4714464..48a040d3 100644 --- a/config/example_config_test.go +++ b/config/example_config_test.go @@ -24,7 +24,6 @@ package config_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -36,8 +35,7 @@ import ( func getExampleConfigs() (map[string][]byte, error) { examplesPath := "../docs/examples" - files, err := ioutil.ReadDir(examplesPath) - + files, err := os.ReadDir(examplesPath) if err != nil { return nil, err } @@ -62,14 +60,13 @@ func getExampleConfigs() (map[string][]byte, error) { return bytes, nil } -func readFileAndParseConfig(path string, info os.FileInfo) ([]byte, error) { +func readFileAndParseConfig(path string, info os.DirEntry) ([]byte, error) { // Assuming we can parse all .json files in the example config directory if filepath.Ext(info.Name()) != ".json" { return nil, nil } - data, err := ioutil.ReadFile(filepath.Join(path, info.Name())) - + data, err := os.ReadFile(filepath.Join(path, info.Name())) if err != nil { return nil, err } @@ -79,7 +76,6 @@ func readFileAndParseConfig(path string, info os.FileInfo) ([]byte, error) { func TestExampleConfigs(t *testing.T) { bytebytes, err := getExampleConfigs() - if err != nil { t.Errorf("Failed to read configuration files, %s", err) } @@ -91,7 +87,6 @@ func TestExampleConfigs(t *testing.T) { // If the test passes it gets suppressed. logrus.Debugf("Parsing %s", filename) conf, err := config.Bytes(bytes) - if err != nil { t.Errorf("Failed to parse config in %s %s", filename, err) return diff --git a/config/parse.go b/config/parse.go index 49695cb2..07eebcb0 100644 --- a/config/parse.go +++ b/config/parse.go @@ -30,7 +30,6 @@ package config import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -420,7 +419,7 @@ func Path(path string) (*Config, error) { // File opens a config file and parses it, then returns the valid // configuration, using Bytes() func File(f string) (*Config, error) { - dat, err := ioutil.ReadFile(f) + dat, err := os.ReadFile(f) if err != nil { return nil, fmt.Errorf("failed to read configuration file: %w", err) } @@ -457,8 +456,7 @@ func ReadFiles(p string) (*Config, error) { for _, f := range files { confLog.WithField("file", f).Debug("Reading file") - b, err := ioutil.ReadFile(f) - + b, err := os.ReadFile(f) if err != nil { return nil, err } diff --git a/encoder/json_test.go b/encoder/json_test.go index 9065f5c8..0a337d32 100644 --- a/encoder/json_test.go +++ b/encoder/json_test.go @@ -25,7 +25,7 @@ package encoder_test import ( - "io/ioutil" + "os" "testing" "github.com/telenornms/skogul" @@ -73,8 +73,7 @@ func testJSON(t *testing.T, file string, match bool) { func parseJSON(t *testing.T, file string) (*skogul.Container, []byte) { t.Helper() - b, err := ioutil.ReadFile(file) - + b, err := os.ReadFile(file) if err != nil { t.Logf("Failed to read test data file: %v", err) t.FailNow() diff --git a/log.go b/log.go index 43c3ab43..61779690 100644 --- a/log.go +++ b/log.go @@ -24,7 +24,7 @@ package skogul import ( - "io/ioutil" + "io" "strings" "github.com/sirupsen/logrus" @@ -36,7 +36,7 @@ var skogulLogger = logrus.New() func ConfigureLogger(requestedLoglevel string, logtimestamp bool, logFormat string) { // Disable output from the root logger; all logging is delegated through hooks logrus.SetLevel(logrus.TraceLevel) - logrus.SetOutput(ioutil.Discard) + logrus.SetOutput(io.Discard) loglevel := GetLogLevelFromString(requestedLoglevel) skogulLogger.SetLevel(loglevel) diff --git a/parser/influxdb_test.go b/parser/influxdb_test.go index 626fcb41..4d22e96a 100644 --- a/parser/influxdb_test.go +++ b/parser/influxdb_test.go @@ -25,7 +25,7 @@ package parser_test import ( "fmt" - "io/ioutil" + "os" "strings" "testing" "time" @@ -108,8 +108,7 @@ func TestInfluxDBLineParseWithoutTimestamp(t *testing.T) { } func TestInfluxDBParseFile(t *testing.T) { - b, err := ioutil.ReadFile("./testdata/influxdb.txt") - + b, err := os.ReadFile("./testdata/influxdb.txt") if err != nil { t.Errorf("Failed to read test data file: %v", err) return @@ -259,8 +258,7 @@ func TestInfluxDBParseTelegrafCmdLine(t *testing.T) { } func TestInfluxDBParseTelegrafCmdLines(t *testing.T) { - b, err := ioutil.ReadFile("./testdata/influxdb_procstat.txt") - + b, err := os.ReadFile("./testdata/influxdb_procstat.txt") if err != nil { t.Errorf("Failed to read test data file: %v", err) return @@ -323,9 +321,9 @@ func TestInfluxDBParseDoubleBackslashEscape(t *testing.T) { t.Errorf("expected parsed tag to equal %s, got %s", name, _container.Metrics[0].Metadata["name"]) } } -func TestInfluxDBParseTelegrafSystemdUnitLines(t *testing.T) { - b, err := ioutil.ReadFile("./testdata/influxdb_systemd_units.txt") +func TestInfluxDBParseTelegrafSystemdUnitLines(t *testing.T) { + b, err := os.ReadFile("./testdata/influxdb_systemd_units.txt") if err != nil { t.Errorf("Failed to read test data file: %v", err) return diff --git a/parser/json_test.go b/parser/json_test.go index 11fb757e..d18ee794 100644 --- a/parser/json_test.go +++ b/parser/json_test.go @@ -25,7 +25,7 @@ package parser_test import ( - "io/ioutil" + "os" "testing" "github.com/telenornms/skogul/parser" @@ -51,8 +51,7 @@ func BenchmarkSkogulJSONParse(b *testing.B) { } func TestJSONParse(t *testing.T) { - b, err := ioutil.ReadFile("./testdata/raw.json") - + b, err := os.ReadFile("./testdata/raw.json") if err != nil { t.Errorf("Failed to read test data file: %v", err) return @@ -72,8 +71,7 @@ func TestJSONParse(t *testing.T) { } func TestJSONArrayParse(t *testing.T) { - b, err := ioutil.ReadFile("./testdata/raw_array.json") - + b, err := os.ReadFile("./testdata/raw_array.json") if err != nil { t.Errorf("Failed to read test data file: %v", err) return diff --git a/parser/mnr_test.go b/parser/mnr_test.go index a4b828ab..85b35e3c 100644 --- a/parser/mnr_test.go +++ b/parser/mnr_test.go @@ -23,7 +23,7 @@ package parser_test import ( - "io/ioutil" + "os" "testing" "time" @@ -170,7 +170,7 @@ func TestMNRExtractValues(t *testing.T) { } func TestMNROnDataset(t *testing.T) { - b, err := ioutil.ReadFile("./testdata/mnr.txt") + b, err := os.ReadFile("./testdata/mnr.txt") if err != nil { t.Errorf("Failed to read test data file: %v", err) return diff --git a/parser/structured_data_test.go b/parser/structured_data_test.go index 55ae1937..e9676870 100644 --- a/parser/structured_data_test.go +++ b/parser/structured_data_test.go @@ -25,7 +25,7 @@ package parser_test import ( "fmt" - "io/ioutil" + "os" "testing" "github.com/telenornms/skogul/parser" @@ -166,7 +166,7 @@ func TestStructuredDataParseNoContentResultsInOneMetric(t *testing.T) { } func TestStructuredDataOnDataset(t *testing.T) { - b, err := ioutil.ReadFile("./testdata/structured_data.txt") + b, err := os.ReadFile("./testdata/structured_data.txt") if err != nil { t.Errorf("Failed to read test data file: %v", err) return diff --git a/receiver/http.go b/receiver/http.go index 3fc8c835..7263fa97 100644 --- a/receiver/http.go +++ b/receiver/http.go @@ -30,8 +30,8 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" + "os" "strings" "sync/atomic" @@ -170,13 +170,15 @@ func (rcvr receiver) ServeHTTP(w http.ResponseWriter, r *http.Request) { "code": code, "remoteAddress": r.RemoteAddr, "requestUri": r.RequestURI, - "ContentLength": r.ContentLength}).WithError(err).Warnf("HTTP request failed") + "ContentLength": r.ContentLength, + }).WithError(err).Warnf("HTTP request failed") } else if rcvr.settings.Log204OK { httpLog.WithFields(log.Fields{ "code": code, "remoteAddress": r.RemoteAddr, "requestUri": r.RequestURI, - "ContentLength": r.ContentLength}).Infof("HTTP request ok") + "ContentLength": r.ContentLength, + }).Infof("HTTP request ok") } answer(w, r, code, err) } @@ -193,7 +195,8 @@ func (f fallback) ServeHTTP(w http.ResponseWriter, r *http.Request) { "code": code, "remoteAddress": r.RemoteAddr, "requestUri": r.RequestURI, - "ContentLength": r.ContentLength}).WithError(err).Warnf("HTTP request failed%s", extra) + "ContentLength": r.ContentLength, + }).WithError(err).Warnf("HTTP request failed%s", extra) if f.hasAuth { code = 401 err = fmt.Errorf("Invalid credentials") @@ -207,7 +210,7 @@ func loadClientCertificateCAs(paths []string) (*x509.CertPool, error) { httpLog.Debugf("Loading Client Certificates from %d file(s)", len(paths)) pool := x509.NewCertPool() for _, path := range paths { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { return nil, fmt.Errorf("failed to read certificate file: %w", err) } diff --git a/sender/snmp_test.go b/sender/snmp_test.go index e9bf51e0..e35b36dc 100644 --- a/sender/snmp_test.go +++ b/sender/snmp_test.go @@ -2,8 +2,8 @@ package sender_test import ( "fmt" - "io/ioutil" "log" + "os" "testing" "time" @@ -82,7 +82,7 @@ func TestSnmpSenderTest(t *testing.T) { } func loadJsonFile(t *testing.T, file string) (*skogul.Container, []byte) { - b, _ := ioutil.ReadFile(file) + b, _ := os.ReadFile(file) container, _ := parser.SkogulJSON{}.Parse(b) diff --git a/transformer/timestamp_test.go b/transformer/timestamp_test.go index 4ed6b352..d5da528b 100644 --- a/transformer/timestamp_test.go +++ b/transformer/timestamp_test.go @@ -25,16 +25,16 @@ package transformer_test import ( "encoding/json" - "github.com/telenornms/skogul" - "github.com/telenornms/skogul/transformer" - "io/ioutil" + "os" "testing" "time" + + "github.com/telenornms/skogul" + "github.com/telenornms/skogul/transformer" ) func TestTimestampParse(t *testing.T) { - b, err := ioutil.ReadFile("./testdata/data-with-timestamp.json") - + b, err := os.ReadFile("./testdata/data-with-timestamp.json") if err != nil { t.Errorf("Could not read json data file: %v", err) return @@ -42,7 +42,6 @@ func TestTimestampParse(t *testing.T) { var jsonData map[string]interface{} err = json.Unmarshal(b, &jsonData) - if err != nil { t.Errorf("Could not parse JSON data: %v", err) return @@ -56,7 +55,6 @@ func TestTimestampParse(t *testing.T) { } jsonTimestamp, err := time.Parse(time.RFC3339, jTimestamp) - if err != nil { t.Errorf("Failed to parse original timestamp from JSON file: %v (%s)", err, jTimestamp) return