Files
athens/pkg/storage/minio/minio.go
Marwan Sulaiman 1ea2969432 pkg/storage: add err ops (#465)
* pkg/storage: add err ops

* fix tests

* fix tests
2018-08-13 11:24:58 -04:00

39 lines
1015 B
Go

package minio
import (
"fmt"
"github.com/gomods/athens/pkg/errors"
"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) {
const op errors.Op = "minio.NewStorage"
minioClient, err := minio.New(endpoint, accessKeyID, secretAccessKey, useSSL)
if err != nil {
return nil, errors.E(op, 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, errors.E(op, err)
}
}
return &storageImpl{minioClient, bucketName}, nil
}