storage

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultEngine = New(Config{
	UploadDir: os.Getenv("UPLOAD_DIR"),
	ServerURL: os.Getenv("SERVER_URL"),
})

DefaultEngine instance for standard project usage

Functions

This section is empty.

Types

type Config

type Config struct {
	Mode      StorageMode
	UploadDir string // Base upload folder (e.g. "public/uploads")
	ServerURL string // Base server URL (e.g. "http://localhost:4000")
}

Config holds runtime storage settings

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine implements domain-agnostic file storage

func New

func New(cfg Config) *Engine

New creates a new Storage Engine

func (*Engine) Delete

func (e *Engine) Delete(relativePath string) bool

Delete removes a file from local storage safely

func (*Engine) ResolveImageUrl

func (e *Engine) ResolveImageUrl(pathOrUrl string) string

ResolveImageUrl resolves any relative path into a client-accessible full URL

func (*Engine) Serve

func (e *Engine) Serve(relativePath string) ([]byte, string, error)

Serve reads a file from storage and determines its MIME type

func (*Engine) ToRelativeImageUrl

func (e *Engine) ToRelativeImageUrl(pathOrUrl string) string

ToRelativeImageUrl normalizes any URL/path into domain-agnostic "uploads/..."

func (*Engine) Upload

func (e *Engine) Upload(data []byte, originalName, subDir string) (*UploadResult, error)

Upload writes a binary buffer into target storage directory safely

type StorageMode

type StorageMode string
const (
	ModeLocal StorageMode = "local"
	ModeS3    StorageMode = "s3"
)

type UploadResult

type UploadResult struct {
	URL     string `json:"url"`     // Relative path (e.g. "uploads/products/image.png")
	FullURL string `json:"fullUrl"` // Absolute URL (e.g. "http://localhost:4000/uploads/products/image.png")
	Path    string `json:"path"`    // Relative storage path for deletion
	Name    string `json:"name"`    // Final sanitized filename
}

UploadResult contains the normalized paths and URLs of an uploaded file

Jump to

Keyboard shortcuts

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