|
|
@@ -1,4 +1,4 @@
|
|
|
-package utils
|
|
|
+package file_server
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
@@ -11,10 +11,12 @@ import (
|
|
|
"sync"
|
|
|
)
|
|
|
|
|
|
-var defaultFileBucket = "file"
|
|
|
-var defaultIconBucket = "icon"
|
|
|
-var defaultLocation = "us-east-1"
|
|
|
-var minioServerPool *sync.Pool
|
|
|
+type MinioConfig struct {
|
|
|
+ EndPoint string `json:"endPoint"`
|
|
|
+ AccessKey string `json:"accessKey"`
|
|
|
+ SecretKey string `json:"secretKey"`
|
|
|
+ UseSSL bool `json:"useSSL"`
|
|
|
+}
|
|
|
|
|
|
var defaultConfig = &MinioConfig{
|
|
|
EndPoint: "http://114.116.19.14:9000",
|
|
|
@@ -23,7 +25,13 @@ var defaultConfig = &MinioConfig{
|
|
|
UseSSL: false,
|
|
|
}
|
|
|
|
|
|
-// DestFile 文件
|
|
|
+var (
|
|
|
+ minioServerPool *sync.Pool
|
|
|
+ defaultFileBucket = "file"
|
|
|
+ defaultIconBucket = "icon"
|
|
|
+ defaultLocation = "us-east-1"
|
|
|
+)
|
|
|
+
|
|
|
type DestFile struct {
|
|
|
FileName string
|
|
|
FileUrl string
|
|
|
@@ -40,19 +48,6 @@ func init() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-type MinioFileObject struct {
|
|
|
- ObjectName string
|
|
|
- FilePath string
|
|
|
- ContentType string
|
|
|
-}
|
|
|
-
|
|
|
-type MinioConfig struct {
|
|
|
- EndPoint string `json:"endPoint"`
|
|
|
- AccessKey string `json:"accessKey"`
|
|
|
- SecretKey string `json:"secretKey"`
|
|
|
- UseSSL bool `json:"useSSL"`
|
|
|
-}
|
|
|
-
|
|
|
func (c *MinioConfig) validate() error {
|
|
|
if c.EndPoint == "" {
|
|
|
return errors.New("EndPoint host not specified")
|
|
|
@@ -130,11 +125,11 @@ func (m *MinioServe) uploadFile(objectName, filePath string) (*DestFile, error)
|
|
|
ctx := context.Background()
|
|
|
bBucketExist := m.checkBuckets(ctx)
|
|
|
if !bBucketExist {
|
|
|
- return nil, errors.New("Bucket不存在")
|
|
|
+ return nil, errors.New("bucket不存在")
|
|
|
}
|
|
|
|
|
|
contentType := "application/octet-stream"
|
|
|
- uinfo, err := m.Client.FPutObject(ctx, defaultFileBucket, objectName, filePath, minio.PutObjectOptions{
|
|
|
+ info, err := m.Client.FPutObject(ctx, defaultFileBucket, objectName, filePath, minio.PutObjectOptions{
|
|
|
ContentType: contentType,
|
|
|
})
|
|
|
|
|
|
@@ -143,12 +138,11 @@ func (m *MinioServe) uploadFile(objectName, filePath string) (*DestFile, error)
|
|
|
}
|
|
|
|
|
|
fileExt := path.Ext(objectName)
|
|
|
-
|
|
|
url := fmt.Sprintf("%s/%s/%s", defaultConfig.EndPoint, defaultFileBucket, objectName)
|
|
|
targetFile := &DestFile{
|
|
|
FileName: objectName,
|
|
|
FileUrl: url,
|
|
|
- FileSize: uinfo.Size,
|
|
|
+ FileSize: info.Size,
|
|
|
FileExt: fileExt,
|
|
|
FileMimeType: "",
|
|
|
}
|