40 lines
837 B
Go
40 lines
837 B
Go
package dal
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/minio/minio-go/v7"
|
|
"io"
|
|
)
|
|
|
|
const (
|
|
bucketAnswers = "squizanswer"
|
|
)
|
|
|
|
type Storer struct {
|
|
client *minio.Client
|
|
}
|
|
|
|
func New(ctx context.Context, minioClient *minio.Client) (*Storer, error) {
|
|
if ok, err := minioClient.BucketExists(ctx, bucketAnswers); !ok {
|
|
if err := minioClient.MakeBucket(ctx, bucketAnswers, minio.MakeBucketOptions{}); err != nil {
|
|
return nil, err
|
|
}
|
|
} else if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Storer{
|
|
client: minioClient,
|
|
}, nil
|
|
}
|
|
|
|
func (s *Storer) PutAnswer(ctx context.Context, file io.Reader, quizId, name string, question uint64, size int64) error {
|
|
if _, err := s.client.PutObject(ctx, bucketAnswers, fmt.Sprintf("%s/%d/%s", quizId, question, name), file, size,
|
|
minio.PutObjectOptions{}); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|