minio/minio.go

46 lines
829 B
Go
Raw Normal View History

2023-01-06 04:56:26 +00:00
package minio
import (
2023-01-08 13:39:17 +00:00
"context"
2023-01-06 04:56:26 +00:00
"errors"
"fmt"
min "github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
func Init(cfg Config) (*Client, error) {
if err := cfg.validate(); err != nil {
return nil, err
}
2023-01-08 13:40:20 +00:00
fmt.Println("cfg", cfg)
2023-01-06 04:56:26 +00:00
client, err := min.New(cfg.Endpoint, &min.Options{
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
Secure: cfg.UseSSL,
})
// return if error
if err != nil {
return nil, err
}
// health check
if client.IsOffline() {
return nil, errors.New("minio is currently offline")
}
fmt.Printf("⚡️[minio]: connected to %s \n", cfg.Endpoint)
2023-01-08 13:39:17 +00:00
buckets, err := client.ListBuckets(context.Background())
fmt.Println("buckets", buckets)
fmt.Println("err", err)
2023-01-06 04:56:26 +00:00
// return
return &Client{
client: client,
cfg: cfg,
}, nil
}