-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminio.go
More file actions
54 lines (49 loc) · 1.22 KB
/
minio.go
File metadata and controls
54 lines (49 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Auth : acer
* Desc : minio
* Time : 2020/9/6 14:44
*/
package services
import (
"bfimpl/services/log"
"github.com/astaxie/beego"
"github.com/minio/minio-go"
)
var client *minio.Client
func SetMinIOClient(c *minio.Client) {
client = c
}
func MinIOClient() *minio.Client {
if client == nil {
InitIO()
}
return client
}
func InitIO() {
endpoint := beego.AppConfig.String("endpoint")
accessKeyID := beego.AppConfig.String("accessKeyID")
secretAccessKey := beego.AppConfig.String("secretAccessKey")
// 初使化 minio client对象。
minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, false)
if err != nil {
log.GLogger.Critical("init minio client err:%s\n", err.Error())
}
SetMinIOClient(minioClient)
InitBucket("default")
// minio Client初使化成功
log.GLogger.Info("minio client init success.")
}
func InitBucket(bucket string) {
// 创建一个default bucket
location := "us-east-1"
// 检查存储桶是否已经存在。
exists, err := MinIOClient().BucketExists(bucket)
if err == nil && exists {
log.GLogger.Info("We already own %s\n", bucket)
return
}
err = MinIOClient().MakeBucket(bucket, location)
if err != nil {
log.GLogger.Error("create bucket err:%s", err.Error())
}
}