package minio import ( "context" "fmt" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" "io" "iot_manager_service/config" "iot_manager_service/util/logger" ) type FileObject struct { Bucket string ObjectName string ObjectSize int64 Reader io.Reader } var minioClient *minio.Client func InitMinio() { cfg := config.Instance() client, err := minio.New(cfg.Minio.Endpoint, &minio.Options{ Creds: credentials.NewStaticV4(cfg.Minio.AccessKey, cfg.Minio.SecretKey, ""), Secure: false, }) if err != nil { panic(fmt.Sprintf("InitMinio err = %s", err.Error())) } minioClient = client } func PutFile(fileObject FileObject) error { ctx := context.Background() _, err := minioClient.PutObject(ctx, fileObject.Bucket, fileObject.ObjectName, fileObject.Reader, fileObject.ObjectSize, minio.PutObjectOptions{}) if err != nil { logger.Logger.Errorf("PutObject fail, err = %s", err.Error()) return err } return nil }