Documentation
¶
Index ¶
- func NewDevelopment(opts ...DevelopmentOption) (simplecontent.Service, func(), error)
- func NewProduction(opts ...ProductionOption) (simplecontent.Service, error)
- func NewTesting(t *testing.T, opts ...TestingOption) simplecontent.Service
- func TestService(t *testing.T) simplecontent.Service
- type DevelopmentOption
- type ProductionOption
- type TestingOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewDevelopment ¶
func NewDevelopment(opts ...DevelopmentOption) (simplecontent.Service, func(), error)
NewDevelopment creates a service configured for local development.
Features:
- In-memory database (instant startup, no setup required)
- Filesystem storage at ./dev-data/ (persistent across restarts)
- Content-based URLs (/api/v1)
- Logging enabled (helpful for debugging)
- All features enabled (admin API, previews, events)
Returns:
- Service instance
- Cleanup function (call with defer to remove dev-data directory)
- Error if setup fails
Example:
svc, cleanup, err := simplecontent.NewDevelopment()
if err != nil {
log.Fatal(err)
}
defer cleanup()
// Use service...
func NewProduction ¶
func NewProduction(opts ...ProductionOption) (simplecontent.Service, error)
NewProduction creates a service configured for production deployment.
Features:
- Database from environment (DATABASE_TYPE, DATABASE_URL)
- Storage from environment (STORAGE_BACKEND, AWS_S3_BUCKET, etc.)
- URL strategy from environment (URL_STRATEGY, CDN_BASE_URL, etc.)
- Event logging enabled
- Security best practices
- Validation of required configuration
Required Environment Variables:
- DATABASE_TYPE: "postgres" (required for production)
- DATABASE_URL: PostgreSQL connection string
- STORAGE_BACKEND: "s3" or "fs"
- AWS_S3_BUCKET: S3 bucket name (if using S3)
- AWS_S3_REGION: S3 region (if using S3)
Optional Environment Variables:
- CDN_BASE_URL: CDN base URL for downloads
- URL_STRATEGY: "cdn", "content-based", or "storage-delegated"
- OBJECT_KEY_GENERATOR: "git-like", "tenant-aware", etc.
Example:
svc, err := simplecontent.NewProduction()
if err != nil {
log.Fatal(err)
}
// Use service in production...
func NewTesting ¶
func NewTesting(t *testing.T, opts ...TestingOption) simplecontent.Service
NewTesting creates a service configured for unit and integration tests.
Features:
- In-memory database (isolated per test)
- In-memory storage (fast, no disk I/O)
- No event logging (cleaner test output)
- Automatic cleanup via t.Cleanup()
- Supports parallel test execution
The testing.T parameter enables automatic cleanup when the test completes.
Example:
func TestMyFeature(t *testing.T) {
svc := simplecontent.NewTesting(t)
// Use service in test...
// Automatic cleanup when test completes
}
func TestService ¶
func TestService(t *testing.T) simplecontent.Service
TestService is a convenience function that creates a test service This is an alias for NewTesting with no options
Types ¶
type DevelopmentOption ¶
type DevelopmentOption func(*devConfig)
DevelopmentOption is a functional option for NewDevelopment
func WithDevPort ¶
func WithDevPort(port string) DevelopmentOption
WithDevPort sets the development server port
func WithDevStorage ¶
func WithDevStorage(dir string) DevelopmentOption
WithDevStorage sets the development storage directory
type ProductionOption ¶
type ProductionOption func(*prodConfig)
ProductionOption is a functional option for NewProduction
func WithProdDatabase ¶
func WithProdDatabase(dbType, url string) ProductionOption
WithProdDatabase sets the production database configuration
func WithProdStorage ¶
func WithProdStorage(backend string) ProductionOption
WithProdStorage sets the production storage backend
type TestingOption ¶
type TestingOption func(*testConfig)
TestingOption is a functional option for NewTesting
func WithTestFixtures ¶
func WithTestFixtures() TestingOption
WithTestFixtures enables test fixtures (sample data)