Files
athens/pkg/storage/minio/minio.go
marpio cde250728a Implement Minio storage (#128)
* add minio dep

* implement minio storage

* fix travis.yml

* start minio in background
2018-05-07 18:13:11 -07:00

37 lines
907 B
Go

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
}