feat: update config minio

This commit is contained in:
hanif salafi 2026-01-02 16:58:45 +07:00
parent d811d11ecc
commit a69899a48d
2 changed files with 31 additions and 15 deletions

View File

@ -2,9 +2,10 @@ package config
import (
"context"
"log"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"log"
)
// MinioSetup struct
@ -30,26 +31,41 @@ func (_minio *MinioStorage) ConnectMinio() (*minio.Client, error) {
bucketName := _minio.Cfg.ObjectStorage.MinioStorage.BucketName
location := _minio.Cfg.ObjectStorage.MinioStorage.Location
// Log connection attempt
log.Printf("[MinIO] Attempting to connect to MinIO at endpoint: %s (SSL: %v)", endpoint, useSSL)
// Initialize minio client object.
minioClient, errInit := minio.New(endpoint, &minio.Options{
Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
Secure: useSSL,
})
if errInit != nil {
log.Fatalln(errInit)
log.Printf("[MinIO] ERROR: Failed to initialize MinIO client. Endpoint: %s, SSL: %v, Error: %v", endpoint, useSSL, errInit)
return nil, errInit
}
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)
log.Printf("[MinIO] MinIO client initialized successfully. Checking bucket: %s", bucketName)
// Check if bucket exists first
exists, errBucketExists := minioClient.BucketExists(ctx, bucketName)
if errBucketExists != nil {
log.Printf("[MinIO] ERROR: Failed to check if bucket exists. Bucket: %s, Error: %v", bucketName, errBucketExists)
return nil, errBucketExists
}
return minioClient, errInit
if exists {
log.Printf("[MinIO] Bucket '%s' already exists and is accessible", bucketName)
} else {
// Try to create the bucket
log.Printf("[MinIO] Bucket '%s' does not exist. Attempting to create it in location: %s", bucketName, location)
err := minioClient.MakeBucket(ctx, bucketName, minio.MakeBucketOptions{Region: location})
if err != nil {
log.Printf("[MinIO] ERROR: Failed to create bucket. Bucket: %s, Location: %s, Error: %v", bucketName, location, err)
return nil, err
}
log.Printf("[MinIO] Successfully created bucket '%s' in location '%s'", bucketName, location)
}
log.Printf("[MinIO] Successfully connected to MinIO and bucket '%s' is ready", bucketName)
return minioClient, nil
}

View File

@ -27,7 +27,7 @@ prettier = true
endpoint = "is3.cloudhost.id"
access-key-id = "YRP1RM617986USRU6NN8"
secret-access-key = "vfbwQDYb1m7nfzo4LVEz90BIyOWfBMZ6bfGQbqDO"
use-ssl = false
use-ssl = true
bucket-name = "mikulnews"
location = "us-east-1"