inital commit

This commit is contained in:
2022-05-09 14:52:18 +02:00
commit d88552c57f
12 changed files with 461 additions and 0 deletions

41
internal/s3/minio.go Normal file
View 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
View 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)
}