edge-connect-client/cmd/cli/main.go
Stephan Lo f1ee439c61 refactor: structure core logic by application use cases
Restructures the internal business logic from a generic `services` package to a use-case-driven design under `internal/application`.

Each primary function of the application (`app`, `instance`, `cloudlet`, `apply`) now resides in its own package. This clarifies the architecture and makes it easier to navigate and extend.

- Moved service implementations to `internal/application/<usecase>/`.
- Kept ports and domain models in `internal/core/`.
- Updated `main.go` and CLI adapters to reflect the new paths.
- Added missing `RefreshAppInstance` method to satisfy the service interface.
- Verified the change with a full build and test run.
2025-10-09 00:00:51 +02:00

42 lines
1.7 KiB
Go

package main
import (
"os"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/adapters/driven/edgeconnect"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/adapters/driving/cli"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/application/app"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/application/cloudlet"
"edp.buildth.ing/DevFW-CICD/edge-connect-client/internal/application/instance"
)
func main() {
// Präsentationsschicht: Simple dependency wiring - no complex container needed
// 1. Infrastructure Layer: Create EdgeConnect client (concrete implementation)
baseURL := getEnvOrDefault("EDGE_CONNECT_BASE_URL", "https://console.mobiledgex.net")
username := os.Getenv("EDGE_CONNECT_USERNAME")
password := os.Getenv("EDGE_CONNECT_PASSWORD")
var client *edgeconnect.Client
if username != "" && password != "" {
client = edgeconnect.NewClientWithCredentials(baseURL, username, password)
} else {
client = edgeconnect.NewClient(baseURL)
}
// 2. Application Layer: Create services with dependency injection (client implements repository interfaces)
appService := app.NewService(client) // client implements AppRepository
instanceService := instance.NewService(client) // client implements AppInstanceRepository
cloudletService := cloudlet.NewService(client) // client implements CloudletRepository
// 3. Presentation Layer: Execute CLI driven adapters with injected services (simple parameter passing)
cli.ExecuteWithServices(appService, instanceService, cloudletService)
}
func getEnvOrDefault(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}