s3manager-web/minio.go

40 lines
818 B
Go
Raw Normal View History

2017-02-22 11:18:20 +01:00
package main
import (
"os"
minio "github.com/minio/minio-go"
)
2017-03-09 21:20:40 +01:00
// NewMinioClient creates a new Minio client
func NewMinioClient() *minio.Client {
2017-02-22 11:18:20 +01:00
var err error
2017-03-09 21:20:40 +01:00
var client *minio.Client
2017-02-22 11:18:20 +01:00
s3Endpoint := os.Getenv("S3_ENDPOINT")
if len(s3Endpoint) == 0 {
s3Endpoint = "s3.amazonaws.com"
}
s3AccessKeyID := os.Getenv("S3_ACCESS_KEY_ID")
if len(s3AccessKeyID) == 0 {
2017-03-09 21:20:40 +01:00
panic("Please set S3_ACCESS_KEY_ID")
2017-02-22 11:18:20 +01:00
}
s3SecretAccessKey := os.Getenv("S3_SECRET_ACCESS_KEY")
if len(s3SecretAccessKey) == 0 {
2017-03-09 21:20:40 +01:00
panic("Please set S3_SECRET_ACCESS_KEY")
2017-02-22 11:18:20 +01:00
}
if os.Getenv("V2_SIGNING") == "true" {
2017-03-09 21:20:40 +01:00
client, err = minio.NewV2(s3Endpoint, s3AccessKeyID, s3SecretAccessKey, true)
2017-02-22 11:18:20 +01:00
} else {
2017-03-09 21:20:40 +01:00
client, err = minio.New(s3Endpoint, s3AccessKeyID, s3SecretAccessKey, true)
2017-02-22 11:18:20 +01:00
}
if err != nil {
2017-03-09 21:20:40 +01:00
panic(err)
2017-02-22 11:18:20 +01:00
}
2017-03-09 21:20:40 +01:00
return client
2017-02-22 11:18:20 +01:00
}