Storage (S3)
core.IStorage — object storage over aws-sdk-go-v2, compatible with S3 and S3-compatible services (MinIO, etc.).
Setup
go
store, err := core.NewStorage(env)Configuration (see env.md):
S3_ENDPOINT=... # optional (S3-compatible endpoints, e.g. MinIO)
S3_REGION=ap-southeast-1
S3_ACCESS_KEY=...
S3_SECRET_KEY=...
S3_BUCKET=my-bucket
S3_FORCE_PATH_STYLE=true # usually needed for MinIOOperations
go
// upload
err := store.Put("avatars/u1.png", fileReader, "image/png")
// download
body, err := store.Get("avatars/u1.png")
defer body.Close()
io.Copy(dst, body)
// presigned GET URL (temporary public link)
url, err := store.PresignGet("avatars/u1.png", 15*time.Minute)
// delete
err = store.Delete("avatars/u1.png", "avatars/old.png")Interface
go
type IStorage interface {
Put(key string, body io.Reader, contentType string) IError
Get(key string) (io.ReadCloser, IError)
Delete(keys ...string) IError
PresignGet(key string, ttl time.Duration) (string, IError)
}Get streams the object (io.ReadCloser) — remember to Close() it.