feat: refactor for using app config
This commit is contained in:
@ -5,8 +5,8 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"gitea.local/admin/hspguard/internal/config"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
)
|
||||
@ -15,27 +15,9 @@ type FileStorage struct {
|
||||
client *minio.Client
|
||||
}
|
||||
|
||||
func New() *FileStorage {
|
||||
endpoint := os.Getenv("MINIO_ENDPOINT")
|
||||
if endpoint == "" {
|
||||
log.Fatalln("MINIO_ENDPOINT env var is required")
|
||||
return nil
|
||||
}
|
||||
|
||||
accessKey := os.Getenv("MINIO_ACCESS_KEY")
|
||||
if accessKey == "" {
|
||||
log.Fatalln("MINIO_ACCESS_KEY env var is required")
|
||||
return nil
|
||||
}
|
||||
|
||||
secretKey := os.Getenv("MINIO_SECRET_KEY")
|
||||
if secretKey == "" {
|
||||
log.Fatalln("MINIO_SECRET_KEY env var is required")
|
||||
return nil
|
||||
}
|
||||
|
||||
client, err := minio.New(endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(accessKey, secretKey, ""),
|
||||
func New(cfg *config.AppConfig) *FileStorage {
|
||||
client, err := minio.New(cfg.Minio.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(cfg.Minio.AccessKey, cfg.Minio.SecretKey, ""),
|
||||
Secure: false,
|
||||
})
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user