44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package minio
|
|
|
|
import (
|
|
"context"
|
|
"github.com/minio/minio-go/v7"
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
"log"
|
|
)
|
|
|
|
// MinioConnection membuka koneksi ke Minio.
|
|
func MinioConnection() (*minio.Client, error) {
|
|
ctx := context.Background()
|
|
endpoint := "localhost:9004"
|
|
accessKeyID := "sc6ZiC6dpWMZWmfwukSF"
|
|
secretAccessKey := "Q6MsoOhYFmRctWJLMrPXdV0vwKns8d9tgUJyu1ec"
|
|
useSSL := false
|
|
// Initialize minio client object.
|
|
minioClient, errInit := minio.New(endpoint, &minio.Options{
|
|
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
|
|
Secure: useSSL,
|
|
})
|
|
if errInit != nil {
|
|
log.Fatalln(errInit)
|
|
}
|
|
|
|
// Make a new bucket called dev-minio.
|
|
bucketName := "humas"
|
|
location := "us-east-1"
|
|
|
|
err := minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
|
|
if err != nil {
|
|
// Check to see if we already own this bucket (which happens if you run this twice)
|
|
exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
|
|
if errBucketExists == nil && exists {
|
|
log.Printf("We already own %s\n", bucketName)
|
|
} else {
|
|
log.Fatalln(err)
|
|
}
|
|
} else {
|
|
log.Printf("Successfully created %s\n", bucketName)
|
|
}
|
|
return minioClient, errInit
|
|
}
|