hpds_jkw_web/pkg/minio/index.go

47 lines
1010 B
Go
Raw Permalink Normal View History

package minio
import (
"context"
"git.hpds.cc/Component/logging"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"io"
)
type MinClient struct {
Client *minio.Client
Logger *logging.Logger
}
func NewClient(ak, sak, ep string, useSSL bool, logger *logging.Logger) *MinClient {
opt := &minio.Options{
Creds: credentials.NewStaticV4(ak, sak, ""),
Secure: useSSL,
}
client, err := minio.New(ep, opt)
if err != nil {
return nil
}
return &MinClient{
Client: client,
Logger: logger,
}
}
func (cli *MinClient) UploadObject(fn, dst, bucket string) error {
_, err := cli.Client.FPutObject(context.Background(), bucket, dst, fn, minio.PutObjectOptions{})
if err != nil {
return err
}
return nil
}
func (cli *MinClient) GetObject(dstUrl, bucket string) ([]byte, error) {
f, err := cli.Client.GetObject(context.Background(), bucket, dstUrl, minio.GetObjectOptions{})
if err != nil {
return nil, err
}
imgByte, _ := io.ReadAll(f)
return imgByte, nil
}