Replace deprecated ioutil with io and os (#20776)

* Replace ioutil with io and os

* Replace ioutil in utils/file.go

* Minor fix to tests and excluded files

Co-authored-by: Tim Scheuermann <tim.scheuermann@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Tim Scheuermann
2022-08-09 14:25:46 +03:00
коммит произвёл GitHub
родитель 15b6046a62
Коммит b4570afa90
115 изменённых файлов: 408 добавлений и 475 удалений

Просмотреть файл

@@ -6,7 +6,6 @@ package mlog_test
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
@@ -99,7 +98,7 @@ func TestLoggingAfterInitialized(t *testing.T) {
t.Run(testCase.description, func(t *testing.T) {
var filePath string
if testCase.cfg.Type == "file" {
tempDir, err := ioutil.TempDir(os.TempDir(), "TestLoggingAfterInitialized")
tempDir, err := os.MkdirTemp(os.TempDir(), "TestLoggingAfterInitialized")
require.NoError(t, err)
defer os.Remove(tempDir)
@@ -122,7 +121,7 @@ func TestLoggingAfterInitialized(t *testing.T) {
logger.Shutdown()
if testCase.cfg.Type == "file" {
logs, err := ioutil.ReadFile(filePath)
logs, err := os.ReadFile(filePath)
require.NoError(t, err)
actual := strings.TrimSpace(string(logs))

Просмотреть файл

@@ -10,7 +10,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
@@ -181,12 +180,14 @@ func NewLogger(options ...Option) (*Logger, error) {
// Configure provides a new configuration for this logger.
// Zero or more sources of config can be provided:
// cfgFile - path to file containing JSON
// cfgEscaped - JSON string probably from ENV var
//
// cfgFile - path to file containing JSON
// cfgEscaped - JSON string probably from ENV var
//
// For each case JSON containing log targets is provided. Target name collisions are resolved
// using the following precedence:
// cfgFile > cfgEscaped
//
// cfgFile > cfgEscaped
//
// An optional set of factories can be provided which will be called to create any target
// types or formatters not built-in.
@@ -199,7 +200,7 @@ func (l *Logger) Configure(cfgFile string, cfgEscaped string, factories *Factori
// Add config from file
if cfgFile != "" {
b, err := ioutil.ReadFile(cfgFile)
b, err := os.ReadFile(cfgFile)
if err != nil {
return fmt.Errorf("error reading logger config file %s: %w", cfgFile, err)
}