feat(minio): initial stable release v1.0.0 — Client interface, xerrors, GetObject, doc examples
Add Client interface with PutObject, GetObject, RemoveObject, PresignedGetObject, and HandleError; Component now embeds Client with Native() as escape hatch for operations not covered by the interface. Add xerrors dependency: HandleError maps minio-go error codes to portable typed codes (NoSuchKey → ErrNotFound, AccessDenied → ErrPermissionDenied, BucketAlreadyExists → ErrAlreadyExists, etc.). OnStop sets c.mc = nil for lifecycle consistency. doc.go updated with launcher wiring, upload, presigned URL, GetObject, and HandleError usage examples. API committed as stable. What's included: - Config with Endpoint, AccessKey, SecretKey, UseSSL, Bucket, Region (env-driven, embeddable) - Transport field in Config for test injection (env:"-", nil uses minio-go default) - Client interface: PutObject, GetObject, RemoveObject, PresignedGetObject, HandleError - Component interface: launcher.Component + health.Checkable + Client + Native() - New(logger, cfg) constructor for lifecycle registration via lc.Append - Automatic bucket creation on OnStart if bucket does not exist - Health check via BucketExists at LevelCritical priority - HandleError: maps minio-go ErrorResponse codes to xerrors typed errors - 21 unit tests using mock HTTP transport; no live server required
This commit is contained in:
46
doc.go
Normal file
46
doc.go
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Package minio provides a MinIO (S3-compatible) client with launcher lifecycle
|
||||
and health check integration.
|
||||
|
||||
Register the component with the launcher and use the Client interface in repositories:
|
||||
|
||||
cfg := minio.Config{
|
||||
Endpoint: "minio:9000",
|
||||
AccessKey: "minioadmin",
|
||||
SecretKey: "minioadmin",
|
||||
Bucket: "my-app-assets",
|
||||
}
|
||||
mc := minio.New(logger, cfg)
|
||||
lc.Append(mc) // OnInit + OnStart + OnStop managed automatically
|
||||
health.NewHandler(logger, mc) // mc satisfies health.Checkable
|
||||
|
||||
Uploading an object via the Client interface:
|
||||
|
||||
info, err := mc.PutObject(ctx, "my-app-assets", "products/abc/photo.jpg",
|
||||
reader, size, miniogo.PutObjectOptions{ContentType: "image/jpeg"})
|
||||
|
||||
Generating a pre-signed download URL:
|
||||
|
||||
u, err := mc.PresignedGetObject(ctx, "my-app-assets", "products/abc/photo.jpg", time.Hour, nil)
|
||||
|
||||
Use Native() for operations not covered by Client (e.g. PresignedPutObject, ListObjects):
|
||||
|
||||
url, err := mc.Native().PresignedPutObject(ctx, "my-app-assets", "products/abc/photo.jpg", time.Hour)
|
||||
|
||||
Errors returned by Client methods are already mapped to typed xerrors values. Use errors.As
|
||||
to inspect them:
|
||||
|
||||
var xe *xerrors.Err
|
||||
if errors.As(err, &xe) && xe.Code() == xerrors.ErrNotFound {
|
||||
// object or bucket does not exist
|
||||
}
|
||||
|
||||
When using Native() directly, map errors explicitly with HandleError before returning them:
|
||||
|
||||
obj, err := mc.Native().GetObject(ctx, bucket, key, miniogo.GetObjectOptions{})
|
||||
if err != nil {
|
||||
return HandleError(err) // maps NoSuchKey → ErrNotFound, AccessDenied → ErrPermissionDenied, etc.
|
||||
}
|
||||
defer obj.Close()
|
||||
*/
|
||||
package minio
|
||||
Reference in New Issue
Block a user