From 4435911099488179546d6532e4e0977efb81f7d5 Mon Sep 17 00:00:00 2001 From: eternal-flame-AD Date: Mon, 13 Jan 2025 13:43:05 -0600 Subject: [PATCH] remove deprecated ioutil package Signed-off-by: eternal-flame-AD --- api/application_test.go | 5 ++--- api/plugin.go | 4 ++-- app.go | 3 --- error/handler_test.go | 4 ++-- plugin/manager.go | 4 ++-- test/asserts.go | 3 +-- test/asserts_test.go | 4 ++-- test/tmpdir.go | 3 +-- 8 files changed, 12 insertions(+), 18 deletions(-) diff --git a/api/application_test.go b/api/application_test.go index 8ca23c29e..9e6efe74d 100644 --- a/api/application_test.go +++ b/api/application_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" "mime/multipart" "net/http/httptest" "os" @@ -633,9 +632,9 @@ func mustOpen(f string) *os.File { } func fakeImage(t *testing.T, path string) { - data, err := ioutil.ReadFile("../test/assets/image.png") + data, err := os.ReadFile("../test/assets/image.png") assert.Nil(t, err) // Write data to dst - err = ioutil.WriteFile(path, data, 0o644) + err = os.WriteFile(path, data, 0o644) assert.Nil(t, err) } diff --git a/api/plugin.go b/api/plugin.go index bc0babac5..fcaeeb4cb 100644 --- a/api/plugin.go +++ b/api/plugin.go @@ -3,7 +3,7 @@ package api import ( "errors" "fmt" - "io/ioutil" + "io" "github.com/gin-gonic/gin" "github.com/gotify/location" @@ -385,7 +385,7 @@ func (c *PluginAPI) UpdateConfig(ctx *gin.Context) { } newConf := instance.DefaultConfig() - newconfBytes, err := ioutil.ReadAll(ctx.Request.Body) + newconfBytes, err := io.ReadAll(ctx.Request.Body) if err != nil { ctx.AbortWithError(500, err) return diff --git a/app.go b/app.go index 1a7b0082a..6d117302e 100644 --- a/app.go +++ b/app.go @@ -2,9 +2,7 @@ package main import ( "fmt" - "math/rand" "os" - "time" "github.com/gotify/server/v2/config" "github.com/gotify/server/v2/database" @@ -30,7 +28,6 @@ func main() { mode.Set(Mode) fmt.Println("Starting Gotify version", vInfo.Version+"@"+BuildDate) - rand.Seed(time.Now().UnixNano()) conf := config.Get() if conf.PluginsDir != "" { diff --git a/error/handler_test.go b/error/handler_test.go index fa618d485..4955b82ff 100644 --- a/error/handler_test.go +++ b/error/handler_test.go @@ -3,7 +3,7 @@ package error import ( "encoding/json" "errors" - "io/ioutil" + "io" "net/http/httptest" "testing" @@ -74,7 +74,7 @@ func TestValidationError(t *testing.T) { } func assertJSONResponse(t *testing.T, rec *httptest.ResponseRecorder, code int, json string) { - bytes, _ := ioutil.ReadAll(rec.Body) + bytes, _ := io.ReadAll(rec.Body) assert.Equal(t, code, rec.Code) assert.JSONEq(t, json, string(bytes)) } diff --git a/plugin/manager.go b/plugin/manager.go index b39c3b456..0ea420047 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -6,8 +6,8 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "log" + "os" "path/filepath" "plugin" "strconv" @@ -221,7 +221,7 @@ func (m *Manager) loadPlugins(directory string) error { return nil } - pluginFiles, err := ioutil.ReadDir(directory) + pluginFiles, err := os.ReadDir(directory) if err != nil { return fmt.Errorf("error while reading directory %s", err) } diff --git a/test/asserts.go b/test/asserts.go index 0225a8b61..98d81646f 100644 --- a/test/asserts.go +++ b/test/asserts.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "io" - "io/ioutil" "net/http/httptest" "github.com/stretchr/testify/assert" @@ -12,7 +11,7 @@ import ( // BodyEquals asserts the content from the response recorder with the encoded json of the provided instance. func BodyEquals(t assert.TestingT, obj interface{}, recorder *httptest.ResponseRecorder) { - bytes, err := ioutil.ReadAll(recorder.Body) + bytes, err := io.ReadAll(recorder.Body) assert.Nil(t, err) actual := string(bytes) diff --git a/test/asserts_test.go b/test/asserts_test.go index cdcbeb829..a018ab968 100644 --- a/test/asserts_test.go +++ b/test/asserts_test.go @@ -1,7 +1,7 @@ package test_test import ( - "io/ioutil" + "io" "net/http/httptest" "testing" @@ -43,6 +43,6 @@ func Test_BodyEquals_failing(t *testing.T) { } func Test_UnreaableReader(t *testing.T) { - _, err := ioutil.ReadAll(test.UnreadableReader()) + _, err := io.ReadAll(test.UnreadableReader()) assert.Error(t, err) } diff --git a/test/tmpdir.go b/test/tmpdir.go index 397af0c37..d2a5118b6 100644 --- a/test/tmpdir.go +++ b/test/tmpdir.go @@ -1,7 +1,6 @@ package test import ( - "io/ioutil" "os" "path" ) @@ -23,6 +22,6 @@ func (c TmpDir) Clean() error { // NewTmpDir returns a new handle to a tmp dir. func NewTmpDir(prefix string) TmpDir { - dir, _ := ioutil.TempDir("", prefix) + dir, _ := os.MkdirTemp("", prefix) return TmpDir{dir} }