feat(storage-minio): initial implementation — MinIO/S3 object storage with lifecycle (v1.0.0)
Introduces code.nochebuena.dev/einherjar/storage-minio — the object storage starter for the Einherjar framework. Absorbs the minio package from micro-lib, replacing fmt.Errorf wrapping with core/xerrors. Interfaces (CT-6: one TypeSpec per file): - Provider — PutObject, RemoveObject, GetObject, PresignedGetObject, HandleError - Component — lifecycle.Component + observability.Checkable + Provider + Native() Implementation: - New(logger, cfg) Component — client not created until OnInit - OnInit: minio.New with credentials and transport; bucket existence check - OnStart: BucketExists PING; logs "minio: connected" - OnStop: logs "minio: closing client" (minio-go is stateless; no explicit close) - HealthCheck: BucketExists check; Priority LevelCritical - Native() *miniogo.Client — escape hatch for operations not in Provider - HandleError: maps minio-go errors to xerrors (NotFound, AlreadyExists, Internal) Config (EINHERJAR_MINIO_* env vars): Endpoint(required), AccessKey(required), SecretKey(required), Bucket(required), UseSSL(false), Region(us-east-1) - Component interface embeds observability.Identifiable; identifiable.go implements ModulePath and ModuleVersion via runtime/debug.ReadBuildInfo() — prints in launcher banner
This commit is contained in:
27
errors.go
Normal file
27
errors.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package minio
|
||||
|
||||
import (
|
||||
miniogo "github.com/minio/minio-go/v7"
|
||||
|
||||
"code.nochebuena.dev/einherjar/core/xerrors"
|
||||
)
|
||||
|
||||
// HandleError maps minio-go errors to xerrors types.
|
||||
// Also available as client.HandleError(err).
|
||||
func HandleError(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
resp := miniogo.ToErrorResponse(err)
|
||||
switch resp.Code {
|
||||
case miniogo.NoSuchBucket:
|
||||
return xerrors.NotFound("bucket not found").WithError(err)
|
||||
case miniogo.NoSuchKey:
|
||||
return xerrors.NotFound("object not found").WithError(err)
|
||||
case miniogo.AccessDenied, miniogo.InvalidAccessKeyID:
|
||||
return xerrors.PermissionDenied("access denied").WithError(err)
|
||||
case miniogo.BucketAlreadyExists, miniogo.BucketAlreadyOwnedByYou:
|
||||
return xerrors.AlreadyExists("bucket already exists").WithError(err)
|
||||
}
|
||||
return xerrors.Internal("unexpected storage error").WithError(err)
|
||||
}
|
||||
Reference in New Issue
Block a user