oss请求处理

This commit is contained in:
andy committed 2026-08-19 10:52:55 +08:00
1 parent 18cb51670c
commit a9a4cdf125
18 files changed
+450 -29

No files matched your search

+17
View File
@@ -9,6 +9,7 @@ import (
"net/url"
"path"
"strings"
"time"
)
const OSSACLPublicRead = "public-read"
@@ -37,6 +38,10 @@ type OSSClient interface {
Delete(context.Context, OSSObjectRequest) error
}
type OSSURLSigner interface {
SignGetURL(OSSObjectRequest, time.Duration) (string, error)
}
type OSSError struct {
Status int
Code string
@@ -116,6 +121,17 @@ func (s *OSS) Delete(ctx context.Context, key string) error {
return mapOSSError(err)
}
func (s *OSS) SignReadURL(key string, ttl time.Duration) (string, error) {
if err := validOSSKey(key); err != nil {
return "", err
}
signer, ok := s.client.(OSSURLSigner)
if !ok {
return "", errors.New("OSS client does not support signed URLs")
}
return signer.SignGetURL(OSSObjectRequest{Endpoint: s.config.PublicBaseURL, Bucket: s.config.Bucket, Key: key}, ttl)
}
type ossOperationDiagnostic struct {
Operation string
Status int
@@ -182,3 +198,4 @@ func escapeOSSKey(key string) string {
}
var _ BlobStore = (*OSS)(nil)
var _ BlobURLSigner = (*OSS)(nil)