diff --git a/cmd/config_test.go b/cmd/config_test.go index 7fef7d99..e75eb4c4 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -6,7 +6,6 @@ package cmd_test import ( "bytes" "fmt" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -84,7 +83,7 @@ module1: workers: -5 ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0o644) + os.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{ Path: configFile, @@ -117,7 +116,7 @@ module2: - name: second ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0o644) + os.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{ Path: configFile, @@ -198,7 +197,7 @@ module2: interval-value: 20m ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0o644) + os.WriteFile(configFile, []byte(config), 0o644) // Environment clean := func() { @@ -319,7 +318,7 @@ module1: workers: 10 ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0o644) + os.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{Path: configFile} @@ -339,7 +338,7 @@ module1: workers: 10 ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0o644) + os.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{Path: configFile} @@ -366,7 +365,7 @@ modules: topic: flows2 ` configFile := filepath.Join(t.TempDir(), "config.yaml") - ioutil.WriteFile(configFile, []byte(config), 0o644) + os.WriteFile(configFile, []byte(config), 0o644) c := cmd.ConfigRelatedOptions{ Path: configFile, diff --git a/cmd/orchestrator_test.go b/cmd/orchestrator_test.go index c2e4fce2..3d7819e0 100644 --- a/cmd/orchestrator_test.go +++ b/cmd/orchestrator_test.go @@ -5,7 +5,7 @@ package cmd import ( "bytes" - "io/ioutil" + "os" "path/filepath" "reflect" "strconv" @@ -27,7 +27,7 @@ func TestOrchestratorStart(t *testing.T) { } func TestOrchestratorConfig(t *testing.T) { - tests, err := ioutil.ReadDir("testdata/configurations") + tests, err := os.ReadDir("testdata/configurations") if err != nil { t.Fatalf("ReadDir(%q) error:\n%+v", "testdata/configurations", err) } @@ -36,7 +36,7 @@ func TestOrchestratorConfig(t *testing.T) { continue } t.Run(test.Name(), func(t *testing.T) { - expected, err := ioutil.ReadFile( + expected, err := os.ReadFile( filepath.Join("testdata/configurations", test.Name(), "expected.yaml")) if err != nil { t.Fatalf("ReadFile() error:\n%+v", err) diff --git a/common/helpers/cache/persist.go b/common/helpers/cache/persist.go index 3645ff99..4fa0496f 100644 --- a/common/helpers/cache/persist.go +++ b/common/helpers/cache/persist.go @@ -7,14 +7,13 @@ import ( "bytes" "encoding/gob" "fmt" - "io/ioutil" "os" "path/filepath" ) // Save persists the cache to the specified file func (c *Cache[K, V]) Save(cacheFile string) error { - tmpFile, err := ioutil.TempFile( + tmpFile, err := os.CreateTemp( filepath.Dir(cacheFile), fmt.Sprintf("%s-*", filepath.Base(cacheFile))) if err != nil { diff --git a/common/httpserver/cache.go b/common/httpserver/cache.go index 00b9690c..0c8b0ec6 100644 --- a/common/httpserver/cache.go +++ b/common/httpserver/cache.go @@ -6,7 +6,7 @@ package httpserver import ( "bytes" "crypto" - "io/ioutil" + "io" "time" cache "github.com/chenyahui/gin-cache" @@ -31,7 +31,7 @@ func (c *Component) CacheByRequestBody(expire time.Duration) gin.HandlerFunc { opts := c.commonCacheOptions() opts = append(opts, cache.WithCacheStrategyByRequest(func(gc *gin.Context) (bool, cache.Strategy) { requestBody, err := gc.GetRawData() - gc.Request.Body = ioutil.NopCloser(bytes.NewBuffer(requestBody)) + gc.Request.Body = io.NopCloser(bytes.NewBuffer(requestBody)) if err != nil { return false, cache.Strategy{} } diff --git a/console/docs.go b/console/docs.go index 1a0b4cda..0053b257 100644 --- a/console/docs.go +++ b/console/docs.go @@ -10,7 +10,6 @@ import ( "fmt" "io" "io/fs" - "io/ioutil" "net/http" "regexp" "strings" @@ -74,7 +73,7 @@ func (c *Component) docsHandlerFunc(gc *gin.Context) { } // Markdown rendering to build ToC - content, _ := ioutil.ReadAll(f) + content, _ := io.ReadAll(f) f.Close() if matches[3] == requestedDocument { // That's the one we need to do final rendering on. diff --git a/console/docs_test.go b/console/docs_test.go index a7bd4c60..7bb5eaac 100644 --- a/console/docs_test.go +++ b/console/docs_test.go @@ -5,7 +5,7 @@ package console import ( "fmt" - "io/ioutil" + "io" "net/http" "strings" "testing" @@ -40,7 +40,7 @@ func TestServeDocs(t *testing.T) { t.Errorf("GET /api/v0/console/docs/%s: got status code %d, not 200", tc.Path, resp.StatusCode) } - body, _ := ioutil.ReadAll(resp.Body) + body, _ := io.ReadAll(resp.Body) if !strings.Contains(string(body), tc.Expect) { t.Logf("Body:\n%s", string(body)) t.Errorf("GET /api/v0/console/docs/%s: does not contain %q", diff --git a/inlet/flow/input/file/root.go b/inlet/flow/input/file/root.go index 36c82bb4..672828e6 100644 --- a/inlet/flow/input/file/root.go +++ b/inlet/flow/input/file/root.go @@ -6,8 +6,8 @@ package file import ( "errors" - "io/ioutil" "net" + "os" "time" "gopkg.in/tomb.v2" @@ -50,7 +50,7 @@ func (in *Input) Start() (<-chan []*schema.FlowMessage, error) { in.t.Go(func() error { for idx := 0; true; idx++ { path := in.config.Paths[idx%len(in.config.Paths)] - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { in.r.Err(err).Str("path", path).Msg("unable to read path") return err diff --git a/orchestrator/clickhouse/http.go b/orchestrator/clickhouse/http.go index 9d02d34c..94ec5c7a 100644 --- a/orchestrator/clickhouse/http.go +++ b/orchestrator/clickhouse/http.go @@ -9,8 +9,8 @@ import ( "encoding/csv" "fmt" "io" - "io/ioutil" "net/http" + "os" "strconv" "text/template" "time" @@ -103,7 +103,7 @@ func (c *Component) registerHTTPHandlers() error { w.WriteHeader(http.StatusServiceUnavailable) return } - file, err := ioutil.ReadFile(v.Source) + file, err := os.ReadFile(v.Source) if err != nil { c.r.Err(err).Msg("unable to deliver custom dict csv file") http.Error(w, fmt.Sprintf("unable to deliver custom dict csv file %s", v.Source), http.StatusNotFound) diff --git a/orchestrator/clickhouse/migrations_test.go b/orchestrator/clickhouse/migrations_test.go index 8c457d57..3952f049 100644 --- a/orchestrator/clickhouse/migrations_test.go +++ b/orchestrator/clickhouse/migrations_test.go @@ -8,7 +8,6 @@ import ( "encoding/csv" "fmt" "io" - "io/ioutil" "net/url" "os" "path" @@ -199,7 +198,7 @@ func TestMigration(t *testing.T) { var lastRun map[string]string var lastSteps int - files, err := ioutil.ReadDir("testdata/states") + files, err := os.ReadDir("testdata/states") if err != nil { t.Fatalf("ReadDir(%q) error:\n%+v", "testdata/states", err) }