2023-07-04 16:47:03 -04:00
|
|
|
package media
|
|
|
|
|
|
|
|
import (
|
2023-07-04 18:41:27 -04:00
|
|
|
"errors"
|
|
|
|
|
2023-07-04 16:47:03 -04:00
|
|
|
"git.agecem.com/agecem/agecem-org/config"
|
|
|
|
"github.com/minio/minio-go/v7"
|
|
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewMediaClient(endpoint, accessKeyId, secretAccessKey string, useSSL bool) (*MediaClient, error) {
|
2023-07-04 18:41:27 -04:00
|
|
|
if accessKeyId == "" {
|
|
|
|
return nil, errors.New("accessKeyId was found empty, but cannot be")
|
|
|
|
}
|
|
|
|
|
|
|
|
if secretAccessKey == "" {
|
|
|
|
return nil, errors.New("secretAccessKey was found empty, but cannot be")
|
|
|
|
}
|
|
|
|
|
2023-07-04 16:47:03 -04:00
|
|
|
var mediaClient MediaClient
|
|
|
|
minioClient, err := minio.New(endpoint, &minio.Options{
|
|
|
|
Creds: credentials.NewStaticV4(accessKeyId, secretAccessKey, ""),
|
|
|
|
Secure: useSSL,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return &mediaClient, err
|
|
|
|
}
|
|
|
|
|
|
|
|
mediaClient.MinioClient = *minioClient
|
|
|
|
return &mediaClient, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMediaClientFromViper() (*MediaClient, error) {
|
|
|
|
var cfg config.Config
|
|
|
|
if err := viper.Unmarshal(&cfg); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
mediaClient, err := NewMediaClient(cfg.Server.Documents.Endpoint, cfg.Server.Documents.AccessKeyId, cfg.Server.Documents.SecretAccessKey, cfg.Server.Documents.UseSSL)
|
|
|
|
if err != nil {
|
|
|
|
return mediaClient, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return mediaClient, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type MediaClient struct {
|
|
|
|
MinioClient minio.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MediaClient) foo() string {
|
|
|
|
return "bar"
|
|
|
|
}
|