minio/minio.go

40 lines
693 B
Go

package minio
import (
"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
}
client, err := min.New(cfg.Endpoint, &min.Options{
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
Secure: cfg.UseSSL,
Region: region,
})
// 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)
// return
return &Client{
client: client,
cfg: cfg,
}, nil
}