s3-share/internal/s3/minio.go

42 lines
820 B
Go
Raw Normal View History

2022-05-09 12:52:18 +00:00
package s3
import (
"context"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/sirupsen/logrus"
)
type minioClient struct {
client *minio.Client
bucket string
}
func NewMinio(endpoint, bucket, accessKey, secretAccessKey string, ssl bool) (S3, error) {
logrus.Info("Creating minio client")
client, err := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKey, secretAccessKey, ""),
Secure: ssl,
})
if err != nil {
return nil, err
}
return &minioClient{
client: client,
bucket: bucket,
}, nil
}
func (m *minioClient) GetObject(ctx context.Context, key string) (ObjectReader, error) {
object, err := m.client.GetObject(ctx, m.bucket, key, minio.GetObjectOptions{})
if err != nil {
return nil, err
}
return object, nil
}