完善牧安云哨-中间件

This commit is contained in:
BBIT-Kai
2025-12-29 16:30:55 +08:00
parent b9b8d30ebf
commit f6f8b59c73
30 changed files with 1090 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
package storage
import (
"context"
"errors"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
const (
minioEndpoint = "ai.ronsunny.cn:9000"
minioAccessKey = "minioadmin"
minioSecretKey = "minioadmin"
useSSL = true
)
var client *minio.Client
func Init() error {
if client != nil {
return nil
}
c, err := minio.New(minioEndpoint, &minio.Options{
Creds: credentials.NewStaticV4(minioAccessKey, minioSecretKey, ""),
Secure: useSSL,
})
if err != nil {
return err
}
client = c
return nil
}
func UploadFile(
ctx context.Context,
bucketName string,
objectName string,
filePath string,
contentType string,
) (int64, error) {
if client == nil {
return 0, errors.New("minio client not initialized")
}
info, err := client.FPutObject(
ctx,
bucketName,
objectName,
filePath,
minio.PutObjectOptions{
ContentType: contentType,
},
)
if err != nil {
return 0, err
}
return info.Size, nil
}