Files
athens/pkg/storage/minio/minio.go
Rohan Chakravarthy 0e470d0294 Plumb config - Latest (#627)
* switch proxy to config file

pull in single flight changes

* changes for single-flight

* intermediate stage. All tests passing. pkg still has env refs

* remove all env references

* delete config/env entirely

* fix failing tests

* create the config.toml file as part of dev setup

* create config file only if it doesn't exist

* update Dockerfiles to use config file

* move composing elements to the top

* verbose parameter naming

* newline

* add flag for config file path

* update docs with config file flag

* remove unnecessary nil check

* use filepath.join

* rename redis port to address

* fix path.join

* fix issues after merge

* add vendor dir
2018-09-11 15:04:20 -07:00

45 lines
1.1 KiB
Go

package minio
import (
"fmt"
"github.com/gomods/athens/pkg/config"
"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(conf *config.MinioConfig) (storage.Backend, error) {
const op errors.Op = "minio.NewStorage"
endpoint := conf.Endpoint
accessKeyID := conf.Key
secretAccessKey := conf.Secret
bucketName := conf.Bucket
useSSL := conf.EnableSSL
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
}