This example demonstrates the fundamental usage of the modular framework with a simple web application.
- Modular Application Setup: How to create a basic modular application using
modular.NewStdApplication() - Configuration Management: Using YAML configuration files with environment variable overrides
- Module Registration: Registering and using custom modules (webserver, router, API)
- Service Dependencies: How modules can depend on and interact with each other
- Configuration Validation: Custom validation logic with default values and required fields
- Application Lifecycle: Proper startup, running, and shutdown handling
- Custom webserver module with configurable host/port
- Router module for HTTP request routing
- API module with sample endpoints
- Health check endpoint (
/health) - User management endpoints (
/api/v1/users/,/api/v1/users/{id}) - Environment-specific configuration (dev, test, prod)
- CORS support with configurable origins
cd examples/basic-app
# Build the application
go build -o basic-app .
# Run with default configuration
./basic-app
# Generate a sample configuration file
./basic-app --generate-config yaml config-sample.yamlOnce running, you can test the endpoints:
# Health check
curl http://localhost:8080/health
# List users
curl http://localhost:8080/api/v1/users/
# Get specific user
curl http://localhost:8080/api/v1/users/123The example uses config.yaml for configuration with the following structure:
appName: Application nameenvironment: Environment type (dev, test, prod)server: Server configuration (host, port, timeouts)database: Database settingsfeatures: Feature togglescors: CORS originsadmins: Admin user emails
main.go: Main application file with configuration and module registrationconfig.yaml: Application configurationwebserver/webserver.go: Custom webserver modulerouter/router.go: HTTP router moduleapi/api.go: API endpoints module
This example serves as the foundation for understanding how to build modular applications with the framework.