45 lines
888 B
Go
45 lines
888 B
Go
package mediaStorage
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/minio/minio-go/v7"
|
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type Handler struct {
|
|
*Service
|
|
}
|
|
|
|
type Deps struct {
|
|
Host string
|
|
Port string
|
|
User string
|
|
Password string
|
|
Secure string
|
|
}
|
|
|
|
func NewHandler(deps Deps) *Handler {
|
|
secureMode := false
|
|
if deps.Secure == "true" {
|
|
secureMode = true
|
|
}
|
|
|
|
endpoint := fmt.Sprintf("%s:%s", deps.Host, deps.Port)
|
|
minioClient, err := minio.New(endpoint, &minio.Options{
|
|
Creds: credentials.NewStaticV4(deps.User, deps.Password, ""),
|
|
Secure: secureMode,
|
|
})
|
|
if err != nil {
|
|
log.WithError(err).Fatal("Media storage | Failed to create minio client")
|
|
}
|
|
|
|
log.WithFields(log.Fields{
|
|
"endpoint": endpoint,
|
|
"secure": secureMode,
|
|
}).Debug("Media storage | Created minio client")
|
|
|
|
return &Handler{
|
|
newService(minioClient),
|
|
}
|
|
}
|