37 lines
709 B
Go
37 lines
709 B
Go
package implements
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/minio/minio-go/v7"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type MinIOObjectStorage struct {
|
|
mc *minio.Client
|
|
}
|
|
|
|
func NewMinIOObjectStorage(mc *minio.Client) *MinIOObjectStorage {
|
|
return &MinIOObjectStorage{mc: mc}
|
|
}
|
|
|
|
func (self *MinIOObjectStorage) PutImage(
|
|
ctx context.Context,
|
|
name string,
|
|
r io.Reader,
|
|
size int64,
|
|
) error {
|
|
_, err := self.mc.PutObject(ctx,
|
|
viper.GetString("minio-bucket"), name, r, size, minio.PutObjectOptions{})
|
|
return err
|
|
}
|
|
|
|
func (self *MinIOObjectStorage) GetImage(
|
|
ctx context.Context,
|
|
name string,
|
|
) (io.Reader, error) {
|
|
return self.mc.GetObject(ctx,
|
|
viper.GetString("minio-bucket"), name, minio.GetObjectOptions{})
|
|
}
|