Skip to content

Commit

Permalink
remove deprecated ioutil package
Browse files Browse the repository at this point in the history
Signed-off-by: eternal-flame-AD <[email protected]>
  • Loading branch information
eternal-flame-AD committed Jan 13, 2025
1 parent 5d4d5d0 commit 4435911
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 18 deletions.
5 changes: 2 additions & 3 deletions api/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"mime/multipart"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions api/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"errors"
"fmt"
"io/ioutil"
"io"

"github.com/gin-gonic/gin"
"github.com/gotify/location"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package main

import (
"fmt"
"math/rand"
"os"
"time"

"github.com/gotify/server/v2/config"
"github.com/gotify/server/v2/database"
Expand All @@ -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 != "" {
Expand Down
4 changes: 2 additions & 2 deletions error/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package error
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http/httptest"
"testing"

Expand Down Expand Up @@ -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))
}
4 changes: 2 additions & 2 deletions plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"plugin"
"strconv"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions test/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"net/http/httptest"

"github.com/stretchr/testify/assert"
)

// 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)

Expand Down
4 changes: 2 additions & 2 deletions test/asserts_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package test_test

import (
"io/ioutil"
"io"
"net/http/httptest"
"testing"

Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions test/tmpdir.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package test

import (
"io/ioutil"
"os"
"path"
)
Expand All @@ -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}
}

0 comments on commit 4435911

Please sign in to comment.