fix: 解决 go 版本升级导致的代码警告 (#527)

This commit is contained in:
ssongliu 2023-04-07 11:30:10 +08:00 committed by GitHub
parent 0eb25d8413
commit e45ef455ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 56 additions and 65 deletions

View File

@ -1,7 +1,6 @@
package v1 package v1
import ( import (
"io/ioutil"
"os" "os"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
@ -35,7 +34,7 @@ func (b *BaseApi) LoadDaemonJsonFile(c *gin.Context) {
helper.SuccessWithData(c, "daemon.json is not find in path") helper.SuccessWithData(c, "daemon.json is not find in path")
return return
} }
content, err := ioutil.ReadFile(constant.DaemonJsonPath) content, err := os.ReadFile(constant.DaemonJsonPath)
if err != nil { if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return return

View File

@ -3,7 +3,7 @@ package v1
import ( import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"path" "path"
@ -510,7 +510,7 @@ func (b *BaseApi) LoadFromFile(c *gin.Context) {
return return
} }
content, err := ioutil.ReadFile(req.Path) content, err := os.ReadFile(req.Path)
if err != nil { if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return return
@ -533,7 +533,7 @@ func mergeChunks(fileName string, fileDir string, dstDir string, chunkCount int)
for i := 0; i < chunkCount; i++ { for i := 0; i < chunkCount; i++ {
chunkPath := filepath.Join(fileDir, fmt.Sprintf("%s.%d", fileName, i)) chunkPath := filepath.Join(fileDir, fmt.Sprintf("%s.%d", fileName, i))
chunkData, err := ioutil.ReadFile(chunkPath) chunkData, err := os.ReadFile(chunkPath)
if err != nil { if err != nil {
return err return err
} }
@ -599,14 +599,14 @@ func (b *BaseApi) UploadChunkFiles(c *gin.Context) {
} }
defer emptyFile.Close() defer emptyFile.Close()
chunkData, err := ioutil.ReadAll(uploadFile) chunkData, err := io.ReadAll(uploadFile)
if err != nil { if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrFileUpload, err) helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrFileUpload, err)
return return
} }
chunkPath := filepath.Join(fileDir, fmt.Sprintf("%s.%d", filename, chunkIndex)) chunkPath := filepath.Join(fileDir, fmt.Sprintf("%s.%d", filename, chunkIndex))
err = ioutil.WriteFile(chunkPath, chunkData, 0644) err = os.WriteFile(chunkPath, chunkData, 0644)
if err != nil { if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrFileUpload, err) helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrFileUpload, err)
return return

View File

@ -5,14 +5,15 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/backend/buserr" "io"
"github.com/1Panel-dev/1Panel/backend/utils/docker"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path" "path"
"strings" "strings"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/utils/docker"
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/app/dto/request" "github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response" "github.com/1Panel-dev/1Panel/backend/app/dto/response"
@ -321,7 +322,9 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
if appInstall.HttpsPort > 0 { if appInstall.HttpsPort > 0 {
ports = append(ports, appInstall.HttpsPort) ports = append(ports, appInstall.HttpsPort)
} }
go OperateFirewallPort(nil, ports) go func() {
_ = OperateFirewallPort(nil, ports)
}()
return &appInstall, nil return &appInstall, nil
} }
@ -340,7 +343,7 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
return nil, err return nil, err
} }
defer versionRes.Body.Close() defer versionRes.Body.Close()
body, err := ioutil.ReadAll(versionRes.Body) body, err := io.ReadAll(versionRes.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"math" "math"
"os" "os"
"path" "path"
@ -612,7 +611,7 @@ func updateInstallInfoInDB(appKey, appName, param string, isRestart bool, value
return nil return nil
} }
envPath := fmt.Sprintf("%s/%s/%s/.env", constant.AppInstallDir, appKey, appInstall.Name) envPath := fmt.Sprintf("%s/%s/%s/.env", constant.AppInstallDir, appKey, appInstall.Name)
lineBytes, err := ioutil.ReadFile(envPath) lineBytes, err := os.ReadFile(envPath)
if err != nil { if err != nil {
return err return err
} }

View File

@ -2,7 +2,6 @@ package service
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@ -176,11 +175,11 @@ func handleRedisRecover(redisInfo *repo.RootInfo, recoverFile string, isRollback
if appendonly == "yes" && redisInfo.Version == "6.0.16" { if appendonly == "yes" && redisInfo.Version == "6.0.16" {
itemName = "appendonly.aof" itemName = "appendonly.aof"
} }
input, err := ioutil.ReadFile(recoverFile) input, err := os.ReadFile(recoverFile)
if err != nil { if err != nil {
return err return err
} }
if err = ioutil.WriteFile(composeDir+"/data/"+itemName, input, 0640); err != nil { if err = os.WriteFile(composeDir+"/data/"+itemName, input, 0640); err != nil {
return err return err
} }
} }

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os/exec" "os/exec"
"sort" "sort"
"strconv" "strconv"
@ -267,7 +266,7 @@ func (u *ContainerService) ContainerStats(id string) (*dto.ContainterStats, erro
} }
defer res.Body.Close() defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -339,7 +338,7 @@ func pullImages(ctx context.Context, client *client.Client, image string) error
return err return err
} }
defer out.Close() defer out.Close()
_, err = io.Copy(ioutil.Discard, out) _, err = io.Copy(io.Discard, out)
if err != nil { if err != nil {
return err return err
} }

View File

@ -10,7 +10,6 @@ import (
"github.com/1Panel-dev/1Panel/backend/buserr" "github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/utils/docker" "github.com/1Panel-dev/1Panel/backend/utils/docker"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/volume" "github.com/docker/docker/api/types/volume"
) )
@ -37,14 +36,14 @@ func (u *ContainerService) PageVolume(req dto.SearchWithPage) (int64, interface{
} }
var ( var (
data []dto.Volume data []dto.Volume
records []*types.Volume records []*volume.Volume
) )
sort.Slice(list.Volumes, func(i, j int) bool { sort.Slice(list.Volumes, func(i, j int) bool {
return list.Volumes[i].CreatedAt > list.Volumes[j].CreatedAt return list.Volumes[i].CreatedAt > list.Volumes[j].CreatedAt
}) })
total, start, end := len(list.Volumes), (req.Page-1)*req.PageSize, req.Page*req.PageSize total, start, end := len(list.Volumes), (req.Page-1)*req.PageSize, req.Page*req.PageSize
if start > total { if start > total {
records = make([]*types.Volume, 0) records = make([]*volume.Volume, 0)
} else { } else {
if end >= total { if end >= total {
end = total end = total
@ -119,7 +118,7 @@ func (u *ContainerService) CreateVolume(req dto.VolumeCreat) error {
} }
} }
} }
options := volume.VolumeCreateBody{ options := volume.CreateOptions{
Name: req.Name, Name: req.Name,
Driver: req.Driver, Driver: req.Driver,
DriverOpts: stringsToMap(req.Options), DriverOpts: stringsToMap(req.Options),

View File

@ -3,7 +3,6 @@ package service
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
"time" "time"
@ -170,7 +169,7 @@ func (u *CronjobService) HandleRmExpired(backType, backupDir string, cronjob *mo
} }
return return
} }
files, err := ioutil.ReadDir(backupDir) files, err := os.ReadDir(backupDir)
if err != nil { if err != nil {
global.LOG.Errorf("read dir %s failed, err: %v", backupDir, err) global.LOG.Errorf("read dir %s failed, err: %v", backupDir, err)
return return

View File

@ -5,7 +5,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"regexp" "regexp"
@ -339,7 +338,7 @@ func (u *MysqlService) UpdateVariables(updatas []dto.MysqlVariablesUpdate) error
var files []string var files []string
path := fmt.Sprintf("%s/mysql/%s/conf/my.cnf", constant.AppInstallDir, app.Name) path := fmt.Sprintf("%s/mysql/%s/conf/my.cnf", constant.AppInstallDir, app.Name)
lineBytes, err := ioutil.ReadFile(path) lineBytes, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err
} }

View File

@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -215,7 +214,7 @@ type redisConfig struct {
func confSet(redisName string, changeConf []redisConfig) error { func confSet(redisName string, changeConf []redisConfig) error {
path := fmt.Sprintf("%s/redis/%s/conf/redis.conf", constant.AppInstallDir, redisName) path := fmt.Sprintf("%s/redis/%s/conf/redis.conf", constant.AppInstallDir, redisName)
lineBytes, err := ioutil.ReadFile(path) lineBytes, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err
} }

View File

@ -4,7 +4,6 @@ import (
"bufio" "bufio"
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@ -66,7 +65,7 @@ func (u *DockerService) LoadDockerConf() *dto.DaemonJsonConf {
if _, err := os.Stat(constant.DaemonJsonPath); err != nil { if _, err := os.Stat(constant.DaemonJsonPath); err != nil {
return &dto.DaemonJsonConf{Status: status, Version: version} return &dto.DaemonJsonConf{Status: status, Version: version}
} }
file, err := ioutil.ReadFile(constant.DaemonJsonPath) file, err := os.ReadFile(constant.DaemonJsonPath)
if err != nil { if err != nil {
return &dto.DaemonJsonConf{Status: status, Version: version} return &dto.DaemonJsonConf{Status: status, Version: version}
} }
@ -109,7 +108,7 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error {
_, _ = os.Create(constant.DaemonJsonPath) _, _ = os.Create(constant.DaemonJsonPath)
} }
file, err := ioutil.ReadFile(constant.DaemonJsonPath) file, err := os.ReadFile(constant.DaemonJsonPath)
if err != nil { if err != nil {
return err return err
} }
@ -151,7 +150,7 @@ func (u *DockerService) UpdateConf(req dto.DaemonJsonConf) error {
if err != nil { if err != nil {
return err return err
} }
if err := ioutil.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil { if err := os.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil {
return err return err
} }

View File

@ -8,7 +8,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@ -174,7 +173,7 @@ func (u *ImageService) ImageBuild(req dto.ImageBuild) (string, error) {
return return
} }
defer res.Body.Close() defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body) body, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
global.LOG.Errorf("build image %s failed, err: %v", req.Name, err) global.LOG.Errorf("build image %s failed, err: %v", req.Name, err)
_, _ = file.WriteString(fmt.Sprintf("build image %s failed, err: %v", req.Name, err)) _, _ = file.WriteString(fmt.Sprintf("build image %s failed, err: %v", req.Name, err))
@ -275,7 +274,7 @@ func (u *ImageService) ImageLoad(req dto.ImageLoad) error {
if err != nil { if err != nil {
return err return err
} }
content, err := ioutil.ReadAll(res.Body) content, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,7 +3,6 @@ package service
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"io/ioutil"
"os" "os"
"path" "path"
"strings" "strings"
@ -190,7 +189,7 @@ func (u *ImageRepoService) handleRegistries(newHost, delHost, handle string) err
} }
deamonMap := make(map[string]interface{}) deamonMap := make(map[string]interface{})
file, err := ioutil.ReadFile(constant.DaemonJsonPath) file, err := os.ReadFile(constant.DaemonJsonPath)
if err != nil { if err != nil {
return err return err
} }
@ -226,7 +225,7 @@ func (u *ImageRepoService) handleRegistries(newHost, delHost, handle string) err
if err != nil { if err != nil {
return err return err
} }
if err := ioutil.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil { if err := os.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil {
return err return err
} }
return nil return nil

View File

@ -1,15 +1,16 @@
package service package service
import ( import (
"github.com/1Panel-dev/1Panel/backend/app/dto/request" "io"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path" "path"
"strings" "strings"
"time" "time"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
"github.com/1Panel-dev/1Panel/backend/app/dto" "github.com/1Panel-dev/1Panel/backend/app/dto"
"github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/utils/files" "github.com/1Panel-dev/1Panel/backend/utils/files"
@ -67,7 +68,7 @@ func (n NginxService) GetStatus() (response.NginxStatus, error) {
if err != nil { if err != nil {
return response.NginxStatus{}, err return response.NginxStatus{}, err
} }
content, err := ioutil.ReadAll(res.Body) content, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
return response.NginxStatus{}, err return response.NginxStatus{}, err
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
"time" "time"
@ -484,7 +483,7 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
func (u *SnapshotService) saveJson(snapJson SnapshotJson, path string) error { func (u *SnapshotService) saveJson(snapJson SnapshotJson, path string) error {
remarkInfo, _ := json.MarshalIndent(snapJson, "", "\t") remarkInfo, _ := json.MarshalIndent(snapJson, "", "\t")
if err := ioutil.WriteFile(fmt.Sprintf("%s/snapshot.json", path), remarkInfo, 0640); err != nil { if err := os.WriteFile(fmt.Sprintf("%s/snapshot.json", path), remarkInfo, 0640); err != nil {
return err return err
} }
return nil return nil
@ -793,7 +792,7 @@ func (u *SnapshotService) updateLiveRestore(enabled bool) error {
if _, err := os.Stat(constant.DaemonJsonPath); err != nil { if _, err := os.Stat(constant.DaemonJsonPath); err != nil {
return fmt.Errorf("load docker daemon.json conf failed, err: %v", err) return fmt.Errorf("load docker daemon.json conf failed, err: %v", err)
} }
file, err := ioutil.ReadFile(constant.DaemonJsonPath) file, err := os.ReadFile(constant.DaemonJsonPath)
if err != nil { if err != nil {
return err return err
} }
@ -809,7 +808,7 @@ func (u *SnapshotService) updateLiveRestore(enabled bool) error {
if err != nil { if err != nil {
return err return err
} }
if err := ioutil.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil { if err := os.WriteFile(constant.DaemonJsonPath, newJson, 0640); err != nil {
return err return err
} }

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"os" "os"
"runtime" "runtime"
@ -203,7 +203,7 @@ func (u *UpgradeService) loadVersion(isLatest bool, currentVersion string) (stri
return "", err return "", err
} }
defer latestVersionRes.Body.Close() defer latestVersionRes.Body.Close()
version, err := ioutil.ReadAll(latestVersionRes.Body) version, err := io.ReadAll(latestVersionRes.Body)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -231,7 +231,7 @@ func (u *UpgradeService) loadReleaseNotes(path string) (string, error) {
return "", err return "", err
} }
defer releaseNotes.Body.Close() defer releaseNotes.Body.Close()
release, err := ioutil.ReadAll(releaseNotes.Body) release, err := io.ReadAll(releaseNotes.Body)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -1,7 +1,6 @@
package log package log
import ( import (
"io/ioutil"
"log" "log"
"os" "os"
"path" "path"
@ -108,7 +107,7 @@ func NewWriterFromConfig(c *Config) (RollingWriter, error) {
} }
if c.MaxRemain > 0 { if c.MaxRemain > 0 {
writer.rollingfilech = make(chan string, c.MaxRemain) writer.rollingfilech = make(chan string, c.MaxRemain)
dir, err := ioutil.ReadDir(c.LogPath) dir, err := os.ReadDir(c.LogPath)
if err != nil { if err != nil {
mng.Close() mng.Close()
return nil, err return nil, err

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/ioutil" "io"
"net/http" "net/http"
"strings" "strings"
"time" "time"
@ -77,9 +77,9 @@ func OperationLog() gin.HandlerFunc {
formatMap := make(map[string]interface{}) formatMap := make(map[string]interface{})
if len(operationDic.BodyKeys) != 0 { if len(operationDic.BodyKeys) != 0 {
body, err := ioutil.ReadAll(c.Request.Body) body, err := io.ReadAll(c.Request.Body)
if err == nil { if err == nil {
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) c.Request.Body = io.NopCloser(bytes.NewBuffer(body))
} }
bodyMap := make(map[string]interface{}) bodyMap := make(map[string]interface{})
_ = json.Unmarshal(body, &bodyMap) _ = json.Unmarshal(body, &bodyMap)

View File

@ -2,7 +2,7 @@ package client
import ( import (
"fmt" "fmt"
"io/ioutil" "io"
"net" "net"
"os" "os"
"path" "path"
@ -75,7 +75,7 @@ func (s sftpClient) Upload(src, target string) (bool, error) {
return false, err return false, err
} }
defer dstFile.Close() defer dstFile.Close()
ff, err := ioutil.ReadAll(srcFile) ff, err := io.ReadAll(srcFile)
if err != nil { if err != nil {
return false, err return false, err
} }

View File

@ -2,7 +2,6 @@ package client
import ( import (
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
@ -62,7 +61,7 @@ func (f *Ufw) PingStatus() (string, error) {
} }
func (f *Ufw) UpdatePingStatus(enabel string) error { func (f *Ufw) UpdatePingStatus(enabel string) error {
lineBytes, err := ioutil.ReadFile(confPath) lineBytes, err := os.ReadFile(confPath)
if err != nil { if err != nil {
return err return err
} }

View File

@ -3,9 +3,10 @@ package nginx
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/backend/utils/nginx/components" "os"
"io/ioutil"
"strings" "strings"
"github.com/1Panel-dev/1Panel/backend/utils/nginx/components"
) )
var ( var (
@ -96,5 +97,5 @@ func DumpConfig(c *components.Config, style *Style) string {
} }
func WriteConfig(c *components.Config, style *Style) error { func WriteConfig(c *components.Config, style *Style) error {
return ioutil.WriteFile(c.FilePath, []byte(DumpConfig(c, style)), 0644) return os.WriteFile(c.FilePath, []byte(DumpConfig(c, style)), 0644)
} }

View File

@ -6,7 +6,6 @@ import (
"crypto/x509" "crypto/x509"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"testing" "testing"
"time" "time"
@ -68,7 +67,7 @@ func TestSSL(t *testing.T) {
// return // return
//} //}
key, err := ioutil.ReadFile("private.key") key, err := os.ReadFile("private.key")
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -31,6 +31,7 @@
}, },
// //
"skipLibCheck": true, "skipLibCheck": true,
"ignoreDeprecations": "5.0",
"suppressImplicitAnyIndexErrors": true "suppressImplicitAnyIndexErrors": true
}, },
// "include": ["./src/views"], // "include": ["./src/views"],