Development Preset Example
This example demonstrates the Development Preset - the fastest way to get started with Simple Content.
Features
- One-line setup:
NewDevelopment() creates a fully configured service
- In-memory database: No PostgreSQL or database setup required
- Filesystem storage: Data persists at
./dev-data/ across restarts
- Automatic cleanup: Cleanup function removes storage directory
Quick Start
go run main.go
What This Example Shows
- Service Creation - One line to create a working service
- Upload Content - Upload documents and images
- Derived Content - Create thumbnails from images
- Download Content - Download uploaded files
- Content Details - Get comprehensive information about content
Code Walkthrough
Create Service
svc, cleanup, err := presets.NewDevelopment()
if err != nil {
log.Fatal(err)
}
defer cleanup() // Remove ./dev-data/ when done
Upload Content
content, err := svc.UploadContent(ctx, simplecontent.UploadContentRequest{
OwnerID: uuid.New(),
TenantID: uuid.New(),
Name: "Development Guide",
DocumentType: "text/plain",
Reader: strings.NewReader("This is a guide for local development."),
FileName: "dev-guide.txt",
})
Create Derived Content
thumbnail, err := svc.UploadDerivedContent(ctx, simplecontent.UploadDerivedContentRequest{
ParentID: imageID,
DerivationType: "thumbnail",
Variant: "thumbnail_256",
Reader: thumbnailReader,
FileName: "screenshot_thumb.png",
MimeType: "image/png",
})
Customization
The development preset supports customization options:
// Custom storage directory
svc, cleanup, err := presets.NewDevelopment(
presets.WithDevStorage("./my-custom-dir"),
)
// Custom port (for future server integration)
svc, cleanup, err := presets.NewDevelopment(
presets.WithDevPort("3000"),
)
When to Use
Use the Development Preset when:
- Learning Simple Content for the first time
- Prototyping new features
- Local development without database setup
- Testing integration with your application
- Running demos and presentations
Next Steps