Documentation
¶
Index ¶
- Constants
- func IsBlobAutoLoad(ctx context.Context) bool
- func IsBlobWriteEnabled(ctx context.Context) bool
- func WithBlobAutoLoad(ctx context.Context, enabled bool) context.Context
- func WithBlobService(ctx context.Context, svc Service) context.Context
- func WithBlobWriteEnabled(ctx context.Context, enabled bool) context.Context
- type Blob
- func (b *Blob) AfterFind(tx *gorm.DB) error
- func (b *Blob) BeforeSave(tx *gorm.DB) error
- func (b *Blob) BlobID() string
- func (b *Blob) Get(ctx context.Context) (string, error)
- func (b Blob) GormDataType() string
- func (b *Blob) IsSet() bool
- func (b *Blob) Metadata() BlobMetadata
- func (b *Blob) Scan(value interface{}) error
- func (b *Blob) Set(value string)
- func (b *Blob) SetContentType(contentType string)
- func (b *Blob) String() string
- func (b *Blob) Value() (driver.Value, error)
- type BlobMetadata
- type Service
Constants ¶
const ( BlobWriteEnabledKey blobContextKey = "blob_write_enabled" BlobAutoLoadKey blobContextKey = "blob_auto_load" BlobServiceKey blobContextKey = "blob_service" )
Variables ¶
This section is empty.
Functions ¶
func IsBlobAutoLoad ¶
IsBlobAutoLoad checks if auto-load is enabled (default: false)
func IsBlobWriteEnabled ¶
IsBlobWriteEnabled checks if blob writes are enabled (default: true)
func WithBlobAutoLoad ¶
WithBlobAutoLoad controls whether blobs auto-load from S3 on query
func WithBlobService ¶
WithBlobService sets the blobstore service in context
Types ¶
type Blob ¶
type Blob struct {
// contains filtered or unexported fields
}
Blob is a GORM custom type that stores large strings in S3 The database column stores JSONB metadata including the S3 key The actual content is stored in S3 at: {org_id}/{owner_type}/{owner_id}/{blob_id}
func (*Blob) BeforeSave ¶
BeforeSave implements GORM hook for automatic S3 upload
func (Blob) GormDataType ¶
GormDataType returns the database column type
func (*Blob) Scan ¶
Scan implements database/sql.Scanner Reads the blob metadata from database (JSONB column)
func (*Blob) SetContentType ¶
SetContentType sets the content type for the blob
type BlobMetadata ¶
type BlobMetadata struct {
BlobID string `json:"blob_id"` // S3 key (blob_id)
S3Key string `json:"s3_key"` // Full S3 path: org_id/blob_id
Size int64 `json:"size,omitempty"` // Size in bytes
ContentType string `json:"content_type,omitempty"` // MIME type
Checksum string `json:"checksum,omitempty"` // SHA256 checksum
CreatedBy string `json:"created_by,omitempty"` // Account ID who created the blob
CreatedAt string `json:"created_at,omitempty"` // ISO 8601 timestamp
}
BlobMetadata represents the JSONB structure stored in the database
type Service ¶
type Service interface {
// Upload stores blob data in S3 (byte-based, for small payloads)
Upload(ctx context.Context, s3Key string, data []byte) error
// Download retrieves blob data from S3 (byte-based, for small payloads)
Download(ctx context.Context, s3Key string) ([]byte, error)
// UploadStream stores blob data in S3 (streaming, for large payloads)
// Returns SHA256 checksum
UploadStream(ctx context.Context, s3Key string, reader io.Reader) (checksum string, err error)
// DownloadStream retrieves blob data from S3 (streaming, for large payloads)
// Returns io.ReadCloser that must be closed by caller
DownloadStream(ctx context.Context, s3Key string) (io.ReadCloser, error)
// GetMetadata retrieves blob metadata without downloading content
GetMetadata(ctx context.Context, s3Key string) (size int64, contentType string, err error)
}
Service provides blob storage operations with S3
func GetBlobService ¶
GetBlobService retrieves the blobstore service from context