Documentation
¶
Index ¶
- Variables
- type Config
- type Engine
- func (e *Engine) Delete(relativePath string) bool
- func (e *Engine) ResolveImageUrl(pathOrUrl string) string
- func (e *Engine) Serve(relativePath string) ([]byte, string, error)
- func (e *Engine) ToRelativeImageUrl(pathOrUrl string) string
- func (e *Engine) Upload(data []byte, originalName, subDir string) (*UploadResult, error)
- type StorageMode
- type UploadResult
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 (*Engine) ResolveImageUrl ¶
ResolveImageUrl resolves any relative path into a client-accessible full URL
func (*Engine) ToRelativeImageUrl ¶
ToRelativeImageUrl normalizes any URL/path into domain-agnostic "uploads/..."
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
Click to show internal directories.
Click to hide internal directories.