forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minio.go
36 lines (30 loc) · 907 Bytes
/
minio.go
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
package minio
import (
"fmt"
"github.com/gomods/athens/pkg/storage"
minio "github.com/minio/minio-go"
)
type storageImpl struct {
minioClient *minio.Client
bucketName string
}
func (s *storageImpl) versionLocation(module, version string) string {
return fmt.Sprintf("%s/%s", module, version)
}
// NewStorage returns a new ListerSaver implementation that stores
// everything under rootDir
func NewStorage(endpoint, accessKeyID, secretAccessKey, bucketName string, useSSL bool) (storage.Backend, error) {
minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
if err != nil {
return nil, err
}
err = minioClient.MakeBucket(bucketName, "")
if err != nil {
// Check to see if we already own this bucket
exists, err := minioClient.BucketExists(bucketName)
if err == nil && !exists {
return nil, err
}
}
return &storageImpl{minioClient, bucketName}, nil
}