Ajouter media/ pour abstraire le client minio
Ajouter media/ à Dockerfile Migrer serverCmd#HandleV1Seed à utiliser media#NewMediaClientFromViper()
This commit is contained in:
parent
fdc2c23096
commit
4f5b451042
3 changed files with 51 additions and 8 deletions
44
media/media.go
Normal file
44
media/media.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package media
|
||||
|
||||
import (
|
||||
"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) {
|
||||
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"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue