Make linter happy and move to os from io/ioutil for reading/writing.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Stanislav Nikitin 2022-08-14 15:49:05 +05:00
parent df5671586e
commit 2ec0e28243
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
28 changed files with 99 additions and 99 deletions

View File

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
* Updated bulma to v 0.7.5.
* Moved from `io/ioutil` to `os` package for reading/writing files and directories.
### Fixed

View File

@ -1,3 +1,4 @@
//nolint:gofmt,gofumpt,goimports
package assets
import "embed"

View File

@ -25,7 +25,6 @@
package context
import (
"io/ioutil"
"os"
"path/filepath"
@ -104,7 +103,7 @@ func (c *Context) LoadConfiguration() {
c.Config = &config.Struct{}
// Read configuration file.
fileData, err2 := ioutil.ReadFile(normalizedConfigPath)
fileData, err2 := os.ReadFile(normalizedConfigPath)
if err2 != nil {
c.Logger.Panic().Err(err2).Msg("Failed to read configuration file")
}

View File

@ -27,7 +27,6 @@ package flatfiles
import (
"database/sql"
"encoding/json"
"io/ioutil"
"os"
"os/user"
"path/filepath"
@ -85,7 +84,7 @@ func (ff *FlatFiles) GetPaste(pasteID int) (*structs.Paste, error) {
pastePath := filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json")
ctx.Logger.Debug().Str("path", pastePath).Msg("Trying to load paste data")
pasteInBytes, err := ioutil.ReadFile(pastePath)
pasteInBytes, err := os.ReadFile(pastePath)
if err != nil {
ctx.Logger.Debug().Err(err).Msg("Failed to read paste from storage")
@ -152,7 +151,7 @@ func (ff *FlatFiles) GetPagedPastes(page int) ([]structs.Paste, error) {
//nolint:exhaustruct
pasteData := &structs.Paste{}
pasteRawData, err := ioutil.ReadFile(filepath.Join(ff.path, "pastes", strconv.Itoa(paste.ID)+".json"))
pasteRawData, err := os.ReadFile(filepath.Join(ff.path, "pastes", strconv.Itoa(paste.ID)+".json"))
if err != nil {
ctx.Logger.Error().Err(err).Msg("Failed to read paste data")
@ -236,7 +235,7 @@ func (ff *FlatFiles) Initialize() {
if _, err := os.Stat(filepath.Join(ff.path, "pastes", "index.json")); err != nil {
ctx.Logger.Warn().Msg("Pastes index file does not exist, will create new one")
} else {
indexData, err := ioutil.ReadFile(filepath.Join(ff.path, "pastes", "index.json"))
indexData, err := os.ReadFile(filepath.Join(ff.path, "pastes", "index.json"))
if err != nil {
ctx.Logger.Fatal().Msg("Failed to read contents of index file!")
}
@ -253,7 +252,7 @@ func (ff *FlatFiles) Initialize() {
func (ff *FlatFiles) SavePaste(paste *structs.Paste) (int64, error) {
ff.writeMutex.Lock()
// Write paste data on disk.
filesOnDisk, _ := ioutil.ReadDir(filepath.Join(ff.path, "pastes"))
filesOnDisk, _ := os.ReadDir(filepath.Join(ff.path, "pastes"))
pasteID := len(filesOnDisk) + 1
paste.ID = pasteID
@ -267,7 +266,7 @@ func (ff *FlatFiles) SavePaste(paste *structs.Paste) (int64, error) {
return 0, err
}
err = ioutil.WriteFile(filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json"), data, 0o600)
err = os.WriteFile(filepath.Join(ff.path, "pastes", strconv.Itoa(pasteID)+".json"), data, 0o600)
if err != nil {
ff.writeMutex.Unlock()
@ -296,7 +295,7 @@ func (ff *FlatFiles) Shutdown() {
return
}
err1 := ioutil.WriteFile(filepath.Join(ff.path, "pastes", "index.json"), indexData, 0o600)
err1 := os.WriteFile(filepath.Join(ff.path, "pastes", "index.json"), indexData, 0o600)
if err1 != nil {
ctx.Logger.Error().Err(err1).Msg("Failed to write index data to file. Pretty sure that you've lost your pastes.")