This commit is contained in:
2026-08-22 21:25:53 +02:00
parent 6585f2464a
commit e6805af3fe
2 changed files with 21 additions and 4 deletions
+21 -3
View File
@@ -4,6 +4,8 @@ import (
"context"
"fmt"
"io"
"net/url"
"strings"
"time"
"github.com/minio/minio-go/v7"
@@ -17,7 +19,6 @@ type Config struct {
SecretKey string
Bucket string
UseSSL bool
PublicUseSSL bool
}
type ObjectInfo struct {
@@ -57,9 +58,13 @@ func NewMinIO(config Config) (*MinIO, error) {
publicClient := client
if config.PublicEndpoint != "" {
publicClient, err = minio.New(config.PublicEndpoint, &minio.Options{
publicEndpoint, secure, err := parseEndpoint(config.PublicEndpoint)
if err != nil {
return nil, fmt.Errorf("parse public endpoint: %w", err)
}
publicClient, err = minio.New(publicEndpoint, &minio.Options{
Creds: credentials.NewStaticV4(config.AccessKey, config.SecretKey, ""),
Secure: config.PublicUseSSL,
Secure: secure,
})
if err != nil {
return nil, fmt.Errorf("create public object storage client: %w", err)
@@ -136,3 +141,16 @@ func (s *MinIO) Put(ctx context.Context, key string, reader io.Reader, size int6
}
var _ Storage = (*MinIO)(nil)
func parseEndpoint(raw string) (host string, secure bool, err error) {
if !strings.Contains(raw, "://") {
raw = "http://" + raw
}
u, err := url.Parse(raw)
if err != nil {
return "", false, err
}
host = u.Host
secure = u.Scheme == "https"
return host, secure, nil
}