inital commit
This commit is contained in:
41
internal/s3/minio.go
Normal file
41
internal/s3/minio.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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
|
||||
}
|
||||
17
internal/s3/s3.go
Normal file
17
internal/s3/s3.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package s3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
)
|
||||
|
||||
type ObjectReader interface {
|
||||
io.Reader
|
||||
io.Seeker
|
||||
io.ReaderAt
|
||||
io.Closer
|
||||
}
|
||||
|
||||
type S3 interface {
|
||||
GetObject(ctx context.Context, key string) (ObjectReader, error)
|
||||
}
|
||||
Reference in New Issue
Block a user