S1-B 收口#3: storage 命名归一 minio.go→s3.go/MinIOStore→S3Store/NewMinIO→NewS3(RustFS 切换 Phase C;调用面=gateway 装配+集成测试两处)
This commit is contained in:
+1
-1
@@ -176,7 +176,7 @@ func main() {
|
|||||||
submitSvc := send.NewSubmitService(db, sf, reviewSvc, pipelineOpts...)
|
submitSvc := send.NewSubmitService(db, sf, reviewSvc, pipelineOpts...)
|
||||||
// Day 44:MinIO 对象存储(号码文件);初始化失败降级 nil → /files/numbers/import 不注册。
|
// Day 44:MinIO 对象存储(号码文件);初始化失败降级 nil → /files/numbers/import 不注册。
|
||||||
var fileImportSvc *send.FileImportService
|
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 {
|
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))
|
a.Lg().Warn("minio_init_failed_file_import_disabled", zap.Error(merr))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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)。
|
// 最小接口 ObjectStore 供服务层依赖倒置(测试用内存实现,见 fileimport_test)。
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
@@ -17,14 +17,14 @@ type ObjectStore interface {
|
|||||||
Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
|
Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// MinIOStore minio-go 实现(启动时 EnsureBucket)。
|
// S3Store minio-go 实现(启动时 EnsureBucket)。
|
||||||
type MinIOStore struct {
|
type S3Store struct {
|
||||||
cli *minio.Client
|
cli *minio.Client
|
||||||
bucket string
|
bucket string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMinIO 按配置建客户端并确保桶存在(幂等)。
|
// NewS3 按配置建客户端并确保桶存在(幂等)。
|
||||||
func NewMinIO(ctx context.Context, endpoint, accessKey, secretKey, bucket string, useSSL bool) (*MinIOStore, error) {
|
func NewS3(ctx context.Context, endpoint, accessKey, secretKey, bucket string, useSSL bool) (*S3Store, error) {
|
||||||
cli, err := minio.New(endpoint, &minio.Options{
|
cli, err := minio.New(endpoint, &minio.Options{
|
||||||
Creds: credentials.NewStaticV4(accessKey, secretKey, ""),
|
Creds: credentials.NewStaticV4(accessKey, secretKey, ""),
|
||||||
Secure: useSSL,
|
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 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。
|
// 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 == "" {
|
if contentType == "" {
|
||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestStorage_RustFS_S3Compat(t *testing.T) {
|
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 {
|
if err != nil {
|
||||||
t.Skipf("对象存储(19010)不可达,跳过(make up): %v", err)
|
t.Skipf("对象存储(19010)不可达,跳过(make up): %v", err)
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@ func TestStorage_RustFS_S3Compat(t *testing.T) {
|
|||||||
t.Fatalf("Put 幂等覆盖失败: %v", err)
|
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.Fatalf("桶已存在时应幂等成功: %v", err)
|
||||||
}
|
}
|
||||||
t.Log("RustFS S3 兼容面通过: MakeBucket 幂等/Put/覆盖写")
|
t.Log("RustFS S3 兼容面通过: MakeBucket 幂等/Put/覆盖写")
|
||||||
|
|||||||
Reference in New Issue
Block a user