Documentation
¶
Overview ¶
Package bsw (block storage wrapper) provides a common interface for generating presigned upload and download URLs for different object storages: Amazon S3 (package s3), Azure Blob Storage (package azure) and the local file system (package fs).
Index ¶
- Constants
- Variables
- func ValidateObjectPath(bucket, key string) error
- func ValidateParts(parts int) error
- type BlockStorageWrapper
- type CompletedPart
- type Object
- func (o *Object) Bucket() string
- func (o *Object) CompleteMultipartUpload(uploadID string, parts []CompletedPart) error
- func (o *Object) DownloadURL(timeout time.Duration) (string, error)
- func (o *Object) Key() string
- func (o *Object) Metadata() map[string]*string
- func (o *Object) MultipartUploadURLs(timeout time.Duration) (urls []string, uploadID string, err error)
- func (o *Object) Parts() int
- func (o *Object) ReplaceMetadata(m map[string]*string) *Object
- func (o *Object) SetMetadata(key, value string) *Object
- func (o *Object) SetValidTill(t int64) *Object
- func (o *Object) StillValid() bool
- func (o *Object) UploadURL(timeout time.Duration) (string, error)
- func (o *Object) ValidTill() int64
- type Option
- type Part
Constants ¶
const MaxParts = 10000
MaxParts is the maximum number of parts in a multipart upload.
Variables ¶
var ( // ErrWrongInvocation is returned when a method is called for an object // that does not support it, e.g. UploadURL for a multipart object. ErrWrongInvocation = errors.Template("wrong invocation"). Code("BSW-0001").StatusCode(500).Severity(errors.Critical) // ErrInvalidConfig is returned when a storage wrapper is misconfigured. ErrInvalidConfig = errors.Template("invalid storage configuration"). Code("BSW-0002").StatusCode(500).Severity(errors.Critical) // ErrNotSupported is returned when a storage does not support an operation. // It wraps errors.ErrUnsupported, so errors.Is(err, errors.ErrUnsupported) is true. ErrNotSupported = errors.Template("operation not supported"). Code("BSW-0003").StatusCode(501).Severity(errors.Medium) // ErrInvalidArgument is returned when an argument, e.g. object key or // number of parts, is not valid. ErrInvalidArgument = errors.Template("invalid argument"). Code("BSW-0004").StatusCode(400).Severity(errors.Tiny) // ErrNotInitialized is returned when a storage wrapper is used before Init. ErrNotInitialized = errors.Template("storage is not initialized"). Code("BSW-0005").StatusCode(500).Severity(errors.Critical) )
Functions ¶
func ValidateObjectPath ¶ added in v0.2.0
ValidateObjectPath checks that bucket and key can be safely used as a path: both are relative slash-separated paths without empty, "." or ".." elements and without backslashes, so bucket may be a directory like "org1/docs". It is used by storages where bucket and key are joined into one path (fs, azure), so an object cannot point outside of the storage root and a key cannot point outside of its bucket.
func ValidateParts ¶ added in v0.2.0
ValidateParts checks that the number of parts is between 1 and MaxParts.
Types ¶
type BlockStorageWrapper ¶
type BlockStorageWrapper interface {
Name() string
PreSignPutObjectURL(o *Object, timeout time.Duration) (string, error)
PreSignMultipartObjectURL(o *Object, timeout time.Duration) (urls []string, uploadID string, err error)
CompleteMultipartUpload(o *Object, uploadID string, parts []CompletedPart) error
PreSignGetObjectURL(o *Object, timeout time.Duration) (string, error)
}
BlockStorageWrapper is implemented by every supported storage.
type CompletedPart ¶
CompletedPart describes an uploaded part of a multipart upload.
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object is an object in a storage.
func NewObject ¶
func NewObject(w BlockStorageWrapper, bucket, key string, opts ...Option) *Object
NewObject returns an object stored in storage w.
func (*Object) CompleteMultipartUpload ¶ added in v0.2.0
func (o *Object) CompleteMultipartUpload(uploadID string, parts []CompletedPart) error
CompleteMultipartUpload merges uploaded parts into a single object.
func (*Object) DownloadURL ¶ added in v0.2.0
DownloadURL returns presigned URL for GET object request.
func (*Object) MultipartUploadURLs ¶
func (o *Object) MultipartUploadURLs(timeout time.Duration) (urls []string, uploadID string, err error)
MultipartUploadURLs returns presigned URLs for PUT object request by parts. When all parts uploaded, call CompleteMultipartUpload to merge parts into a single file.
func (*Object) ReplaceMetadata ¶
ReplaceMetadata replaces object metadata.
func (*Object) SetMetadata ¶
SetMetadata sets a metadata value.
func (*Object) SetValidTill ¶
SetValidTill sets the time (unix seconds) the object is valid till.
func (*Object) StillValid ¶
StillValid returns false if the validity time is set and has passed.
type Option ¶ added in v0.1.0
type Option func(*Object)
Option configures an Object.
func WithMetadata ¶ added in v0.1.0
WithMetadata sets object metadata.
func WithMultiParts ¶ added in v0.1.0
WithMultiParts sets the number of parts for a multipart upload.
func WithValidTill ¶ added in v0.1.0
WithValidTill sets the time (unix seconds) the object is valid till.
type Part ¶ added in v0.2.0
type Part struct {
// Entity tag returned when the part was uploaded.
ETag string
// Part number that identifies the part. This is a positive integer between
// 1 and 10,000.
PartNumber int64
}
Part is the default implementation of CompletedPart.
func (*Part) PartNumberPtr ¶ added in v0.2.0
PartNumberPtr returns a pointer to the part number.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package azure implements bsw.BlockStorageWrapper for Azure Blob Storage.
|
Package azure implements bsw.BlockStorageWrapper for Azure Blob Storage. |
|
Package fs implements bsw.BlockStorageWrapper for the local file system.
|
Package fs implements bsw.BlockStorageWrapper for the local file system. |
|
Package s3 implements bsw.BlockStorageWrapper for Amazon S3 and S3-compatible storages.
|
Package s3 implements bsw.BlockStorageWrapper for Amazon S3 and S3-compatible storages. |