fix: use of ioutil package (#5261)

* fix ioutil.NopCloser

* fix ioutil.ReadAll

* fix ioutil.ReadFile

* fix ioutil.WriteFile

* run goimports -w -format-only ./

* update CHANGELOG.md
This commit is contained in:
Kota
2023-06-25 19:48:23 +09:00
committed by GitHub
parent a04bf251c7
commit 6f803ec9a9
26 changed files with 73 additions and 85 deletions

View File

@@ -19,7 +19,6 @@ package env
import (
"fmt"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"strings"
@@ -119,7 +118,7 @@ func GetRuntimeEnv(key string) (string, error) {
}
var runtimeEnv string
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
return "", err
}

View File

@@ -20,7 +20,6 @@ import (
"context"
"errors"
"io"
"io/ioutil"
"os"
"os/user"
"path/filepath"
@@ -54,7 +53,7 @@ func (ini *IniConfig) Parse(name string) (Configer, error) {
}
func (ini *IniConfig) parseFile(name string) (*IniConfigContainer, error) {
data, err := ioutil.ReadFile(name)
data, err := os.ReadFile(name)
if err != nil {
return nil, err
}

View File

@@ -16,7 +16,6 @@ package config
import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
@@ -173,7 +172,7 @@ name=mysql
}
defer os.Remove(name)
if data, err := ioutil.ReadFile(name); err != nil {
if data, err := os.ReadFile(name); err != nil {
t.Fatal(err)
} else {
cfgData := string(data)

View File

@@ -18,7 +18,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"strconv"
"strings"
@@ -40,7 +40,7 @@ func (js *JSONConfig) Parse(filename string) (config.Configer, error) {
return nil, err
}
defer file.Close()
content, err := ioutil.ReadAll(file)
content, err := io.ReadAll(file)
if err != nil {
return nil, err
}

View File

@@ -15,7 +15,6 @@
package toml
import (
"io/ioutil"
"os"
"strings"
@@ -32,7 +31,7 @@ type Config struct {
// Parse accepts filename as the parameter
func (c *Config) Parse(filename string) (config.Configer, error) {
ctx, err := ioutil.ReadFile(filename)
ctx, err := os.ReadFile(filename)
if err != nil {
return nil, err
}

View File

@@ -32,7 +32,6 @@ import (
"encoding/xml"
"errors"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
@@ -53,7 +52,7 @@ type Config struct{}
// Parse returns a ConfigContainer with parsed xml config map.
func (xc *Config) Parse(filename string) (config.Configer, error) {
context, err := ioutil.ReadFile(filename)
context, err := os.ReadFile(filename)
if err != nil {
return nil, err
}

View File

@@ -26,7 +26,6 @@ package yaml
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"sync"
@@ -66,7 +65,7 @@ func (*Config) ParseData(data []byte) (config.Configer, error) {
// ReadYmlReader Read yaml file to map.
func ReadYmlReader(path string) (cnf map[string]interface{}, err error) {
buf, err := ioutil.ReadFile(path)
buf, err := os.ReadFile(path)
if err != nil {
return
}

View File

@@ -9,7 +9,7 @@ package alils
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httputil"
)
@@ -51,7 +51,7 @@ func (p *LogProject) ListLogStore() (storeNames []string, err error) {
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -96,7 +96,7 @@ func (p *LogProject) GetLogStore(name string) (s *LogStore, err error) {
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -156,7 +156,7 @@ func (p *LogProject) CreateLogStore(name string, ttl, shardCnt int) (err error)
return
}
body, err = ioutil.ReadAll(r.Body)
body, err = io.ReadAll(r.Body)
if err != nil {
return
}
@@ -188,7 +188,7 @@ func (p *LogProject) DeleteLogStore(name string) (err error) {
return
}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -239,7 +239,7 @@ func (p *LogProject) UpdateLogStore(name string, ttl, shardCnt int) (err error)
return
}
body, err = ioutil.ReadAll(r.Body)
body, err = io.ReadAll(r.Body)
if err != nil {
return
}
@@ -277,7 +277,7 @@ func (p *LogProject) ListMachineGroup(offset, size int) (m []string, total int,
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -324,7 +324,7 @@ func (p *LogProject) GetMachineGroup(name string) (m *MachineGroup, err error) {
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -369,7 +369,7 @@ func (p *LogProject) CreateMachineGroup(m *MachineGroup) (err error) {
return
}
body, err = ioutil.ReadAll(r.Body)
body, err = io.ReadAll(r.Body)
if err != nil {
return
}
@@ -408,7 +408,7 @@ func (p *LogProject) UpdateMachineGroup(m *MachineGroup) (err error) {
return
}
body, err = ioutil.ReadAll(r.Body)
body, err = io.ReadAll(r.Body)
if err != nil {
return
}
@@ -440,7 +440,7 @@ func (p *LogProject) DeleteMachineGroup(name string) (err error) {
return
}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -477,7 +477,7 @@ func (p *LogProject) ListConfig(offset, size int) (cfgNames []string, total int,
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -522,7 +522,7 @@ func (p *LogProject) GetConfig(name string) (c *LogConfig, err error) {
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -567,7 +567,7 @@ func (p *LogProject) UpdateConfig(c *LogConfig) (err error) {
return
}
body, err = ioutil.ReadAll(r.Body)
body, err = io.ReadAll(r.Body)
if err != nil {
return
}
@@ -606,7 +606,7 @@ func (p *LogProject) CreateConfig(c *LogConfig) (err error) {
return
}
body, err = ioutil.ReadAll(r.Body)
body, err = io.ReadAll(r.Body)
if err != nil {
return
}
@@ -638,7 +638,7 @@ func (p *LogProject) DeleteConfig(name string) (err error) {
return
}
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -670,7 +670,7 @@ func (p *LogProject) GetAppliedMachineGroups(confName string) (groupNames []stri
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -715,7 +715,7 @@ func (p *LogProject) GetAppliedConfigs(groupName string) (confNames []string, er
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -760,7 +760,7 @@ func (p *LogProject) ApplyConfigToMachineGroup(confName, groupName string) (err
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -792,7 +792,7 @@ func (p *LogProject) RemoveConfigFromMachineGroup(confName, groupName string) (e
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}

View File

@@ -3,7 +3,7 @@ package alils
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httputil"
"strconv"
@@ -41,7 +41,7 @@ func (s *LogStore) ListShards() (shardIDs []int, err error) {
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -98,7 +98,7 @@ func (s *LogStore) PutLogs(lg *LogGroup) (err error) {
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -134,7 +134,7 @@ func (s *LogStore) GetCursor(shardID int, from string) (cursor string, err error
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}
@@ -185,7 +185,7 @@ func (s *LogStore) GetLogsBytes(shardID int, cursor string,
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}

View File

@@ -3,7 +3,7 @@ package alils
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httputil"
)
@@ -54,7 +54,7 @@ func (m *MachineGroup) ListMachines() (ms []*Machine, total int, err error) {
return
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
return
}

View File

@@ -17,7 +17,6 @@ package logs
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"strconv"
"testing"
@@ -378,7 +377,7 @@ func testFileDailyRotate(t *testing.T, fn1, fn2 string) {
if err != nil {
t.FailNow()
}
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
t.FailNow()
}
@@ -413,7 +412,7 @@ func testFileHourlyRotate(t *testing.T, fn1, fn2 string) {
if err != nil {
t.FailNow()
}
content, err := ioutil.ReadFile(file)
content, err := os.ReadFile(file)
if err != nil {
t.FailNow()
}