backend

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchBucketError = &S3Error{
		Code:       ErrNoSuchBucket,
		Message:    "The specified bucket does not exist",
		StatusCode: 404,
	}

	ErrNoSuchKeyError = &S3Error{
		Code:       ErrNoSuchKey,
		Message:    "The specified key does not exist",
		StatusCode: 404,
	}

	ErrNoSuchUploadError = &S3Error{
		Code:       ErrNoSuchUpload,
		Message:    "The specified upload does not exist",
		StatusCode: 404,
	}

	ErrInvalidKeyError = &S3Error{
		Code:       ErrInvalidKey,
		Message:    "The specified key is not valid",
		StatusCode: 400,
	}

	ErrInvalidPartError = &S3Error{
		Code:       ErrInvalidPart,
		Message:    "One or more of the specified parts could not be found",
		StatusCode: 400,
	}

	ErrAccessDeniedError = &S3Error{
		Code:       ErrAccessDenied,
		Message:    "Access Denied",
		StatusCode: 403,
	}

	ErrInternalServerError = &S3Error{
		Code:       ErrInternalError,
		Message:    "We encountered an internal error. Please try again.",
		StatusCode: 500,
	}

	ErrInvalidRangeError = &S3Error{
		Code:       ErrInvalidRange,
		Message:    "The requested range is not satisfiable",
		StatusCode: 416,
	}

	ErrBucketAlreadyExistsError = &S3Error{
		Code:       ErrBucketAlreadyExists,
		Message:    "The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.",
		StatusCode: 409,
	}

	ErrBucketAlreadyOwnedByYouError = &S3Error{
		Code:       ErrBucketAlreadyOwnedByYou,
		Message:    "Your previous request to create the named bucket succeeded and you already own it.",
		StatusCode: 409,
	}

	ErrInvalidBucketNameError = &S3Error{
		Code:       ErrInvalidBucketName,
		Message:    "The specified bucket is not valid.",
		StatusCode: 400,
	}

	ErrBucketNotEmptyError = &S3Error{
		Code:       ErrBucketNotEmpty,
		Message:    "The bucket you tried to delete is not empty.",
		StatusCode: 409,
	}
)

Predefined errors for common cases

Functions

func GetHTTPStatus

func GetHTTPStatus(err error) int

GetHTTPStatus returns the HTTP status code for an error

func IsValidBucketName

func IsValidBucketName(bucket string) error

IsValidBucketName validates a bucket name according to S3 naming rules https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html

Types

type Backend

type Backend interface {
	// Object operations
	GetObject(ctx context.Context, req *GetObjectRequest) (*GetObjectResponse, error)
	HeadObject(ctx context.Context, bucket, key string) (*HeadObjectResponse, error)
	PutObject(ctx context.Context, req *PutObjectRequest) (*PutObjectResponse, error)
	DeleteObject(ctx context.Context, req *DeleteObjectRequest) error

	// Bucket operations
	CreateBucket(ctx context.Context, req *CreateBucketRequest) (*CreateBucketResponse, error)
	DeleteBucket(ctx context.Context, req *DeleteBucketRequest) error
	HeadBucket(ctx context.Context, req *HeadBucketRequest) (*HeadBucketResponse, error)
	ListBuckets(ctx context.Context, ownerID string) (*ListBucketsResponse, error)
	ListObjects(ctx context.Context, req *ListObjectsRequest) (*ListObjectsResponse, error)

	// Multipart upload operations
	CreateMultipartUpload(ctx context.Context, req *CreateMultipartUploadRequest) (*CreateMultipartUploadResponse, error)
	UploadPart(ctx context.Context, req *UploadPartRequest) (*UploadPartResponse, error)
	CompleteMultipartUpload(ctx context.Context, req *CompleteMultipartUploadRequest) (*CompleteMultipartUploadResponse, error)
	AbortMultipartUpload(ctx context.Context, bucket, key, uploadID string) error

	// Backend info
	Type() string
	Close() error
}

Backend defines the interface for storage backends. All methods accept context.Context for cancellation and timeouts. This interface is HTTP-layer agnostic - no framework-specific types.

type BucketInfo

type BucketInfo struct {
	Name         string
	CreationDate time.Time
	Region       string
}

BucketInfo contains metadata about a bucket

type BucketMetadata

type BucketMetadata struct {
	Name         string    `json:"name"`
	Region       string    `json:"region"`
	OwnerID      string    `json:"owner_id"`      // Access key ID of owner
	OwnerDisplay string    `json:"owner_display"` // Display name
	CreationDate time.Time `json:"creation_date"`
	Public       bool      `json:"public"`      // Allow anonymous access
	ObjectLock   bool      `json:"object_lock"` // Object lock enabled
	Versioning   string    `json:"versioning"`  // Enabled, Suspended, or empty
}

BucketMetadata contains complete bucket metadata stored in s3db

type CompleteMultipartUploadRequest

type CompleteMultipartUploadRequest struct {
	Bucket   string
	Key      string
	UploadID string
	Parts    []CompletedPart
}

CompleteMultipartUploadRequest contains parameters for CompleteMultipartUpload

type CompleteMultipartUploadResponse

type CompleteMultipartUploadResponse struct {
	Location string
	Bucket   string
	Key      string
	ETag     string
}

CompleteMultipartUploadResponse contains the result of CompleteMultipartUpload

type CompletedPart

type CompletedPart struct {
	PartNumber int
	ETag       string
}

CompletedPart represents a completed part in multipart upload

type CreateBucketRequest

type CreateBucketRequest struct {
	Bucket            string
	Region            string // From LocationConstraint in request body
	OwnerID           string // Access key ID of the authenticated user
	OwnerDisplayName  string // Display name (optional)
	ObjectLockEnabled bool   // For object lock (future)
	ObjectOwnership   string // BucketOwnerEnforced, BucketOwnerPreferred, ObjectWriter
}

CreateBucketRequest contains parameters for CreateBucket operation

type CreateBucketResponse

type CreateBucketResponse struct {
	Location string // The bucket's location (e.g., /bucket-name)
}

CreateBucketResponse contains the result of CreateBucket operation

type CreateMultipartUploadRequest

type CreateMultipartUploadRequest struct {
	Bucket      string
	Key         string
	ContentType string
}

CreateMultipartUploadRequest contains parameters for InitiateMultipartUpload

type CreateMultipartUploadResponse

type CreateMultipartUploadResponse struct {
	Bucket   string
	Key      string
	UploadID string
}

CreateMultipartUploadResponse contains the result of InitiateMultipartUpload

type DeleteBucketRequest

type DeleteBucketRequest struct {
	Bucket  string
	OwnerID string // For ownership verification
}

DeleteBucketRequest contains parameters for DeleteBucket operation

type DeleteObjectRequest

type DeleteObjectRequest struct {
	Bucket string
	Key    string
}

DeleteObjectRequest contains parameters for DeleteObject operation

type GetObjectRequest

type GetObjectRequest struct {
	Bucket     string
	Key        string
	RangeStart int64 // -1 means not specified
	RangeEnd   int64 // -1 means not specified
}

GetObjectRequest contains parameters for GetObject operation

type GetObjectResponse

type GetObjectResponse struct {
	Body         io.ReadCloser
	ContentType  string
	ContentRange string
	Size         int64
	ETag         string
	LastModified time.Time
	StatusCode   int // 200 for full content, 206 for partial
}

GetObjectResponse contains the result of GetObject operation

type HeadBucketRequest

type HeadBucketRequest struct {
	Bucket string
}

HeadBucketRequest contains parameters for HeadBucket operation

type HeadBucketResponse

type HeadBucketResponse struct {
	Region string
	Name   string
}

HeadBucketResponse contains the result of HeadBucket operation

type HeadObjectResponse

type HeadObjectResponse struct {
	ContentType   string
	ContentLength int64
	ETag          string
	LastModified  time.Time
}

HeadObjectResponse contains the result of HeadObject operation

type ListBucketsResponse

type ListBucketsResponse struct {
	Buckets []BucketInfo
	Owner   OwnerInfo
}

ListBucketsResponse contains the result of ListBuckets operation

type ListObjectsRequest

type ListObjectsRequest struct {
	Bucket       string
	Prefix       string
	Delimiter    string
	MaxKeys      int
	StartAfter   string
	EncodingType string
}

ListObjectsRequest contains parameters for ListObjectsV2 operation

type ListObjectsResponse

type ListObjectsResponse struct {
	Name           string
	Prefix         string
	Delimiter      string
	MaxKeys        int
	KeyCount       int
	IsTruncated    bool
	Contents       []ObjectInfo
	CommonPrefixes []string
}

ListObjectsResponse contains the result of ListObjectsV2 operation

type ObjectInfo

type ObjectInfo struct {
	Key          string
	Size         int64
	LastModified time.Time
	ETag         string
	ContentType  string
	StorageClass string
	IsDir        bool
}

ObjectInfo contains metadata about an object

type OwnerInfo

type OwnerInfo struct {
	ID          string
	DisplayName string
}

OwnerInfo contains owner information

type PutObjectRequest

type PutObjectRequest struct {
	Bucket          string
	Key             string
	Body            io.Reader
	ContentLength   int64
	ContentType     string
	ContentEncoding string
	IsChunked       bool
	DecodedLength   int64 // For aws-chunked encoding
}

PutObjectRequest contains parameters for PutObject operation

type PutObjectResponse

type PutObjectResponse struct {
	ETag string
}

PutObjectResponse contains the result of PutObject operation

type S3Error

type S3Error struct {
	Code       S3ErrorCode
	Message    string
	StatusCode int
	Resource   string
}

S3Error represents a typed S3 error with code and message

func IsS3Error

func IsS3Error(err error) (*S3Error, bool)

IsS3Error checks if an error is an S3Error and returns it

func NewS3Error

func NewS3Error(code S3ErrorCode, message string, statusCode int) *S3Error

NewS3Error creates a new S3Error with the given code

func (*S3Error) Error

func (e *S3Error) Error() string

Error implements the error interface

func (*S3Error) Is

func (e *S3Error) Is(target error) bool

Is implements error comparison for errors.Is()

func (*S3Error) WithResource

func (e *S3Error) WithResource(resource string) *S3Error

WithResource adds a resource path to an S3Error

type S3ErrorCode

type S3ErrorCode string

S3ErrorCode represents standardized S3 error codes

const (
	ErrNoSuchBucket            S3ErrorCode = "NoSuchBucket"
	ErrNoSuchKey               S3ErrorCode = "NoSuchKey"
	ErrNoSuchUpload            S3ErrorCode = "NoSuchUpload"
	ErrInvalidKey              S3ErrorCode = "InvalidKey"
	ErrInvalidPart             S3ErrorCode = "InvalidPart"
	ErrInvalidPartOrder        S3ErrorCode = "InvalidPartOrder"
	ErrAccessDenied            S3ErrorCode = "AccessDenied"
	ErrInternalError           S3ErrorCode = "InternalError"
	ErrEntityTooSmall          S3ErrorCode = "EntityTooSmall"
	ErrEntityTooLarge          S3ErrorCode = "EntityTooLarge"
	ErrInvalidRange            S3ErrorCode = "InvalidRange"
	ErrBucketNotEmpty          S3ErrorCode = "BucketNotEmpty"
	ErrBucketAlreadyExists     S3ErrorCode = "BucketAlreadyExists"
	ErrBucketAlreadyOwnedByYou S3ErrorCode = "BucketAlreadyOwnedByYou"
	ErrInvalidBucketName       S3ErrorCode = "InvalidBucketName"
	ErrMissingParameter        S3ErrorCode = "MissingParameter"
	ErrChecksumMismatch        S3ErrorCode = "XAmzContentChecksumMismatch"
)

type UploadPartRequest

type UploadPartRequest struct {
	Bucket          string
	Key             string
	UploadID        string
	PartNumber      int
	Body            io.Reader
	ContentLength   int64
	ContentEncoding string
	IsChunked       bool
	DecodedLength   int64
}

UploadPartRequest contains parameters for UploadPart operation

type UploadPartResponse

type UploadPartResponse struct {
	ETag       string
	PartNumber int
}

UploadPartResponse contains the result of UploadPart operation

Directories

Path Synopsis
Package multipart provides shared multipart upload functionality for S3-compatible backends.
Package multipart provides shared multipart upload functionality for S3-compatible backends.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL