mirror of
https://github.com/gomods/athens
synced 2026-02-03 11:00:32 +00:00
* 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
45 lines
1.1 KiB
Go
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
|
|
}
|