fixagain
This commit is contained in:
@@ -51,7 +51,6 @@ func main() {
|
|||||||
SecretKey: cfg.StorageSecretKey,
|
SecretKey: cfg.StorageSecretKey,
|
||||||
Bucket: cfg.StorageBucket,
|
Bucket: cfg.StorageBucket,
|
||||||
UseSSL: cfg.StorageUseSSL,
|
UseSSL: cfg.StorageUseSSL,
|
||||||
PublicUseSSL: true,
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("storage unavailable: %v", err)
|
log.Fatalf("storage unavailable: %v", err)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
@@ -17,7 +19,6 @@ type Config struct {
|
|||||||
SecretKey string
|
SecretKey string
|
||||||
Bucket string
|
Bucket string
|
||||||
UseSSL bool
|
UseSSL bool
|
||||||
PublicUseSSL bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ObjectInfo struct {
|
type ObjectInfo struct {
|
||||||
@@ -57,9 +58,13 @@ func NewMinIO(config Config) (*MinIO, error) {
|
|||||||
|
|
||||||
publicClient := client
|
publicClient := client
|
||||||
if config.PublicEndpoint != "" {
|
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, ""),
|
Creds: credentials.NewStaticV4(config.AccessKey, config.SecretKey, ""),
|
||||||
Secure: config.PublicUseSSL,
|
Secure: secure,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("create public object storage client: %w", err)
|
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)
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user