2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 07:57:21 +08:00

fix: lint

This commit is contained in:
2025-09-18 14:48:46 +08:00
parent 821736d06d
commit f6878982ad
3 changed files with 59 additions and 42 deletions

View File

@@ -51,7 +51,7 @@ func (f *FTP) connect() (*ftp.ServerConn, error) {
err = conn.Login(f.config.Username, f.config.Password)
if err != nil {
conn.Quit()
_ = conn.Quit()
return nil, err
}
@@ -64,7 +64,9 @@ func (f *FTP) ensureBasePath() error {
if err != nil {
return err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
// 递归创建路径
parts := strings.Split(f.config.BasePath, "/")
@@ -105,7 +107,9 @@ func (f *FTP) MakeDirectory(directory string) error {
if err != nil {
return err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
remotePath := f.getRemotePath(directory)
@@ -137,7 +141,9 @@ func (f *FTP) DeleteDirectory(directory string) error {
if err != nil {
return err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
remotePath := f.getRemotePath(directory)
return conn.RemoveDir(remotePath)
@@ -159,7 +165,9 @@ func (f *FTP) Delete(files ...string) error {
if err != nil {
return err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
for _, file := range files {
remotePath := f.getRemotePath(file)
@@ -176,7 +184,9 @@ func (f *FTP) Exists(file string) bool {
if err != nil {
return false
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
remotePath := f.getRemotePath(file)
_, err = conn.FileSize(remotePath)
@@ -189,7 +199,9 @@ func (f *FTP) Files(path string) ([]string, error) {
if err != nil {
return nil, err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
remotePath := f.getRemotePath(path)
entries, err := conn.List(remotePath)
@@ -213,14 +225,18 @@ func (f *FTP) Get(file string) ([]byte, error) {
if err != nil {
return nil, err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
remotePath := f.getRemotePath(file)
resp, err := conn.Retr(remotePath)
if err != nil {
return nil, err
}
defer resp.Close()
defer func(resp *ftp.Response) {
_ = resp.Close()
}(resp)
return io.ReadAll(resp)
}
@@ -231,7 +247,9 @@ func (f *FTP) LastModified(file string) (time.Time, error) {
if err != nil {
return time.Time{}, err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
remotePath := f.getRemotePath(file)
entries, err := conn.List(filepath.Dir(remotePath))
@@ -270,7 +288,9 @@ func (f *FTP) Move(oldFile, newFile string) error {
if err != nil {
return err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
oldPath := f.getRemotePath(oldFile)
newPath := f.getRemotePath(newFile)
@@ -315,7 +335,9 @@ func (f *FTP) Put(file, content string) error {
if err != nil {
return err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
remotePath := f.getRemotePath(file)
@@ -334,7 +356,9 @@ func (f *FTP) Size(file string) (int64, error) {
if err != nil {
return 0, err
}
defer conn.Quit()
defer func(conn *ftp.ServerConn) {
_ = conn.Quit()
}(conn)
remotePath := f.getRemotePath(file)
return conn.FileSize(remotePath)

View File

@@ -58,38 +58,31 @@ func NewS3(cfg S3Config) (Storage, error) {
var awsCfg aws.Config
var err error
if cfg.Endpoint != "" {
// 自定义端点(如 MinIO
awsCfg, err = config.LoadDefaultConfig(context.TODO(),
config.WithRegion(cfg.Region),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
cfg.AccessKeyID, cfg.SecretAccessKey, "")),
config.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
URL: cfg.Endpoint,
SigningRegion: cfg.Region,
}, nil
})),
)
} else {
// 标准 AWS S3
awsCfg, err = config.LoadDefaultConfig(context.TODO(),
config.WithRegion(cfg.Region),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
cfg.AccessKeyID, cfg.SecretAccessKey, "")),
)
}
awsCfg, err = config.LoadDefaultConfig(context.TODO(),
config.WithRegion(cfg.Region),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider(
cfg.AccessKeyID, cfg.SecretAccessKey, "")),
)
if err != nil {
return nil, fmt.Errorf("failed to load AWS config: %w", err)
}
// 根据地址模式配置客户端
usePathStyle := cfg.AddressingStyle == S3AddressingStylePath || cfg.ForcePathStyle
client := s3.NewFromConfig(awsCfg, func(o *s3.Options) {
o.UsePathStyle = usePathStyle
})
var client *s3.Client
if cfg.Endpoint != "" {
// 自定义端点
client = s3.NewFromConfig(awsCfg, func(o *s3.Options) {
o.UsePathStyle = usePathStyle
o.BaseEndpoint = aws.String(cfg.Endpoint)
})
} else {
// 标准 AWS S3
client = s3.NewFromConfig(awsCfg, func(o *s3.Options) {
o.UsePathStyle = usePathStyle
})
}
s := &S3{
client: client,
@@ -280,7 +273,7 @@ func (s *S3) Get(file string) ([]byte, error) {
if err != nil {
return nil, err
}
defer output.Body.Close()
defer func(body io.ReadCloser) { _ = body.Close() }(output.Body)
return io.ReadAll(output.Body)
}

View File

@@ -64,8 +64,8 @@ func (s *SFTP) connect() (*sftp.Client, func(), error) {
if _, statErr := os.Stat(s.config.PrivateKey); statErr == nil {
// 私钥文件路径
keyBytes, err := os.ReadFile(s.config.PrivateKey)
if err != nil {
keyBytes, err2 := os.ReadFile(s.config.PrivateKey)
if err2 != nil {
return nil, nil, fmt.Errorf("failed to read private key file: %w", err)
}
signer, err = ssh.ParsePrivateKey(keyBytes)