fix: 处理代码警告 (#2756)

This commit is contained in:
ssongliu 2023-11-01 13:49:30 +08:00 committed by GitHub
parent 0b67c8dfc9
commit 00cad5b586
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 12 deletions

View file

@ -19,6 +19,7 @@ import (
"github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/global"
"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"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
) )
@ -239,7 +240,7 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) {
} }
options := types.ImagePullOptions{} options := types.ImagePullOptions{}
if repo.Auth { if repo.Auth {
authConfig := types.AuthConfig{ authConfig := registry.AuthConfig{
Username: repo.Username, Username: repo.Username,
Password: repo.Password, Password: repo.Password,
} }
@ -336,7 +337,7 @@ func (u *ImageService) ImagePush(req dto.ImagePush) (string, error) {
} }
options := types.ImagePushOptions{} options := types.ImagePushOptions{}
if repo.Auth { if repo.Auth {
authConfig := types.AuthConfig{ authConfig := registry.AuthConfig{
Username: repo.Username, Username: repo.Username,
Password: repo.Password, Password: repo.Password,
} }

View file

@ -98,11 +98,12 @@ func RandStr(n int) string {
} }
func RandStrAndNum(n int) string { func RandStrAndNum(n int) string {
mathRand.Seed(time.Now().UnixNano()) source := mathRand.NewSource(time.Now().UnixNano())
randGen := mathRand.New(source)
const charset = "abcdefghijklmnopqrstuvwxyz0123456789" const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
b := make([]byte, 10) b := make([]byte, n)
for i := range b { for i := range b {
b[i] = charset[mathRand.Int63()%int64(len(charset))] b[i] = charset[randGen.Intn(len(charset)-1)]
} }
return (string(b)) return (string(b))
} }

View file

@ -2,11 +2,12 @@ package ps
import ( import (
"fmt" "fmt"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/process"
"strconv" "strconv"
"testing" "testing"
"time" "time"
"github.com/shirou/gopsutil/v3/host"
"github.com/shirou/gopsutil/v3/process"
) )
func TestPs(t *testing.T) { func TestPs(t *testing.T) {
@ -67,8 +68,8 @@ func TestPs(t *testing.T) {
fmt.Println(ss) fmt.Println(ss)
} }
fmt.Println(fmt.Sprintf("Name: %s PId: %v ParentID: %v Username: %v status:%s startTime: %s numThreads: %v numConnections:%v cpuPercent:%v rss:%s MB IORead: %s IOWrite: %s", fmt.Printf("Name: %s PId: %v ParentID: %v Username: %v status:%s startTime: %s numThreads: %v numConnections:%v cpuPercent:%v rss:%s MB IORead: %s IOWrite: %s \n",
name, pro.Pid, parentID, userName, status, startTime, numThreads, numConnections, cpuPercent, rss, ioRead, ioWrite)) name, pro.Pid, parentID, userName, status, startTime, numThreads, numConnections, cpuPercent, rss, ioRead, ioWrite)
} }
users, err := host.Users() users, err := host.Users()
if err == nil { if err == nil {

View file

@ -8,13 +8,14 @@ import (
"encoding/json" "encoding/json"
"encoding/pem" "encoding/pem"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/backend/utils/files"
"gopkg.in/yaml.v3"
"os" "os"
"path" "path"
"testing" "testing"
"time" "time"
"github.com/1Panel-dev/1Panel/backend/utils/files"
"gopkg.in/yaml.v3"
"github.com/go-acme/lego/v4/acme/api" "github.com/go-acme/lego/v4/acme/api"
"github.com/go-acme/lego/v4/certcrypto" "github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate" "github.com/go-acme/lego/v4/certificate"
@ -105,7 +106,9 @@ func TestAppToV2(t *testing.T) {
oldAppDir := oldDir + "/" + appDefine.Key oldAppDir := oldDir + "/" + appDefine.Key
newAppDir := newDir + "/" + appDefine.Key newAppDir := newDir + "/" + appDefine.Key
if !fileOp.Stat(newAppDir) { if !fileOp.Stat(newAppDir) {
fileOp.CreateDir(newAppDir, 0755) if err := fileOp.CreateDir(newAppDir, 0755); err != nil {
panic(err)
}
} }
// logo // logo
oldLogoPath := oldAppDir + "/metadata/logo.png" oldLogoPath := oldAppDir + "/metadata/logo.png"