diff --git a/cmd/gateway/main.go b/cmd/gateway/main.go index 52c76155..a5c62a93 100644 --- a/cmd/gateway/main.go +++ b/cmd/gateway/main.go @@ -176,7 +176,7 @@ func main() { submitSvc := send.NewSubmitService(db, sf, reviewSvc, pipelineOpts...) // Day 44:MinIO 对象存储(号码文件);初始化失败降级 nil → /files/numbers/import 不注册。 var fileImportSvc *send.FileImportService - if mo, merr := storage.NewMinIO(context.Background(), + if mo, merr := storage.NewS3(context.Background(), cfg.MinIO.Endpoint, cfg.MinIO.AccessKey, cfg.MinIO.SecretKey, cfg.MinIO.Bucket, cfg.MinIO.UseSSL); merr != nil { a.Lg().Warn("minio_init_failed_file_import_disabled", zap.Error(merr)) } else { diff --git a/internal/pkg/storage/minio.go b/internal/pkg/storage/s3.go similarity index 70% rename from internal/pkg/storage/minio.go rename to internal/pkg/storage/s3.go index d060bb2c..fedaae40 100644 --- a/internal/pkg/storage/minio.go +++ b/internal/pkg/storage/s3.go @@ -1,4 +1,4 @@ -// Package storage Day 44:对象存储(MinIO,S3 API)——号码文件/报表/检测结果落桶。 +// Package storage Day 44:对象存储(S3 API;2026-11-13 起后端=RustFS,客户端=minio-go 通用 S3 SDK)——号码文件/报表/检测结果落桶。 // 最小接口 ObjectStore 供服务层依赖倒置(测试用内存实现,见 fileimport_test)。 package storage @@ -17,14 +17,14 @@ type ObjectStore interface { Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error } -// MinIOStore minio-go 实现(启动时 EnsureBucket)。 -type MinIOStore struct { +// S3Store minio-go 实现(启动时 EnsureBucket)。 +type S3Store struct { cli *minio.Client bucket string } -// NewMinIO 按配置建客户端并确保桶存在(幂等)。 -func NewMinIO(ctx context.Context, endpoint, accessKey, secretKey, bucket string, useSSL bool) (*MinIOStore, error) { +// NewS3 按配置建客户端并确保桶存在(幂等)。 +func NewS3(ctx context.Context, endpoint, accessKey, secretKey, bucket string, useSSL bool) (*S3Store, error) { cli, err := minio.New(endpoint, &minio.Options{ Creds: credentials.NewStaticV4(accessKey, secretKey, ""), Secure: useSSL, @@ -41,11 +41,11 @@ func NewMinIO(ctx context.Context, endpoint, accessKey, secretKey, bucket string return nil, fmt.Errorf("storage: make bucket %s: %w", bucket, err) } } - return &MinIOStore{cli: cli, bucket: bucket}, nil + return &S3Store{cli: cli, bucket: bucket}, nil } // Put 实现 ObjectStore。 -func (s *MinIOStore) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error { +func (s *S3Store) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error { if contentType == "" { contentType = "application/octet-stream" } diff --git a/test/integration/storage_test.go b/test/integration/storage_test.go index 3d353fad..f5fa83d8 100644 --- a/test/integration/storage_test.go +++ b/test/integration/storage_test.go @@ -15,7 +15,7 @@ import ( ) func TestStorage_RustFS_S3Compat(t *testing.T) { - s, err := storage.NewMinIO(context.Background(), "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false) + s, err := storage.NewS3(context.Background(), "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false) if err != nil { t.Skipf("对象存储(19010)不可达,跳过(make up): %v", err) } @@ -31,7 +31,7 @@ func TestStorage_RustFS_S3Compat(t *testing.T) { t.Fatalf("Put 幂等覆盖失败: %v", err) } // 二次构造(桶已存在分支) - if _, err := storage.NewMinIO(ctx, "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false); err != nil { + if _, err := storage.NewS3(ctx, "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false); err != nil { t.Fatalf("桶已存在时应幂等成功: %v", err) } t.Log("RustFS S3 兼容面通过: MakeBucket 幂等/Put/覆盖写")