47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
|
|
/*
|
||
|
|
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
|