diff --git a/cmd/lokstra/migration.go b/cmd/lokstra/migration.go index 8db4167b..a24050f3 100644 --- a/cmd/lokstra/migration.go +++ b/cmd/lokstra/migration.go @@ -9,6 +9,7 @@ import ( "time" "github.com/primadi/lokstra/common/utils" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/serviceapi" "github.com/primadi/lokstra/tools/migration_runner" @@ -122,8 +123,7 @@ func executeMigration(subCmd, configFile, migrationDir, dbPoolName string, steps return fmt.Errorf("migrations directory not found: %s", migrationDir) } - // load named-db-pools from config file - if err := lokstra_registry.LoadConfig(cfgFile); err != nil { + if _, err := loader.LoadConfig(cfgFile); err != nil { return fmt.Errorf("failed to load config file '%s': %w", filepath.Base(cfgFile), err) } diff --git a/core/deploy/loader/builder.go b/core/deploy/loader/builder.go index baaaf438..1c96caad 100644 --- a/core/deploy/loader/builder.go +++ b/core/deploy/loader/builder.go @@ -860,6 +860,10 @@ func RegisterDefinitionsForRuntime(registry *deploy.GlobalRegistry, config *sche // LoadConfig loads config and builds ALL deployments into Global registry // Returns error only - deployments are stored in deploy.Global() func LoadConfig(configPaths ...string) (*schema.DeployConfig, error) { + if len(configPaths) == 0 { + configPaths = []string{"config"} + } + config, err := loadConfig(configPaths...) if err != nil { return nil, fmt.Errorf("failed to load config: %w", err) @@ -971,23 +975,19 @@ func LoadConfig(configPaths ...string) (*schema.DeployConfig, error) { registry.StoreDeploymentTopology(deployTopo) } - // Auto-discover and setup named DB pools - // if err := SetupNamedDbPools(registry, config); err != nil { - // return fmt.Errorf("failed to setup named DB pools: %w", err) - // } - + logger.LogDebug("✅ Config loaded successfully from: %v", configPaths) return config, nil } -// LoadNamedDbPoolsFromConfig auto-discovers and sets up named DB pools from config +// LoadDbPoolManagerFromConfig auto-discovers and sets up named DB pools from config // Requires dbpool-manager service to be already registered -func LoadNamedDbPoolsFromConfig() error { +func LoadDbPoolManagerFromConfig() error { registry := deploy.Global() config := registry.GetDeployConfig() - // Check if named-db-pools section exists - if len(config.NamedDbPools) == 0 { - // No named-db-pools section, skip + // Check if dbpool-manager section exists + if len(config.DbPoolManager) == 0 { + // No dbpool-manager section, skip return nil } @@ -1001,7 +1001,7 @@ func LoadNamedDbPoolsFromConfig() error { } // Setup each pool - for poolName, poolConfig := range config.NamedDbPools { + for poolName, poolConfig := range config.DbPoolManager { // Extract DSN or build from components dsn := poolConfig.DSN @@ -1042,7 +1042,7 @@ func LoadNamedDbPoolsFromConfig() error { password := poolConfig.Password if host == "" || database == "" { - return fmt.Errorf("named-db-pools.%s: must provide either 'dsn' or 'host'+'database'", poolName) + return fmt.Errorf("dbpool-manager.%s: must provide either 'dsn' or 'host'+'database'", poolName) } // Build DSN with best practice defaults @@ -1083,7 +1083,7 @@ func LoadNamedDbPoolsFromConfig() error { // Set DSN and Schema for poolName // This also auto-registers the pool as a lazy service - dbPoolManager.SetNamedDbPool(poolName, dsn, schema, poolConfig.RlsContext) + dbPoolManager.SetDbPoolManager(poolName, dsn, schema, poolConfig.RlsContext) logger.LogDebug("✅ Registered DB pool: %s (schema: %s)", poolName, schema) } diff --git a/core/deploy/loader/loader.go b/core/deploy/loader/loader.go index e8295e21..494fd3d1 100644 --- a/core/deploy/loader/loader.go +++ b/core/deploy/loader/loader.go @@ -201,7 +201,7 @@ func applyConfigOverrides(config *schema.DeployConfig) { func mergeConfigs(target, source *schema.DeployConfig) *schema.DeployConfig { result := &schema.DeployConfig{ Configs: mergeMap(target.Configs, source.Configs), - NamedDbPools: mergeMaps(target.NamedDbPools, source.NamedDbPools), + DbPoolManager: mergeMaps(target.DbPoolManager, source.DbPoolManager), MiddlewareDefinitions: mergeMaps(target.MiddlewareDefinitions, source.MiddlewareDefinitions), ServiceDefinitions: mergeMaps(target.ServiceDefinitions, source.ServiceDefinitions), RouterDefinitions: mergeMaps(target.RouterDefinitions, source.RouterDefinitions), // Renamed from Routers diff --git a/core/deploy/loader/resolver/PROVIDER-REGISTRY.md b/core/deploy/loader/resolver/PROVIDER-REGISTRY.md index 75b1fe27..1722514e 100644 --- a/core/deploy/loader/resolver/PROVIDER-REGISTRY.md +++ b/core/deploy/loader/resolver/PROVIDER-REGISTRY.md @@ -139,7 +139,7 @@ configs: host: "prod-db.example.com" db:url: "postgresql://localhost:5432/mydb" # Key with colon -named-db-pools: +dbpool-manager: main: # Simple config reference (no colons in key) host: ${@cfg:database.host} @@ -232,7 +232,7 @@ configs: host: "prod-db.example.com" port: 5432 -named-db-pools: +dbpool-manager: main: host: ${@cfg:db.host} # → "prod-db.example.com" port: ${@cfg:db.port} # → 5432 @@ -502,7 +502,7 @@ configs: aws: region: ${AWS_REGION:us-east-1} # @env provider -named-db-pools: +dbpool-manager: main: # Mix of providers host: ${@cfg:db.host} # @cfg provider diff --git a/core/deploy/schema/lokstra.schema.json b/core/deploy/schema/lokstra.schema.json index 72e67f9e..b31860d9 100644 --- a/core/deploy/schema/lokstra.schema.json +++ b/core/deploy/schema/lokstra.schema.json @@ -385,7 +385,7 @@ } } }, - "named-db-pools": { + "dbpool-manager": { "type": "object", "description": "Named database pool configurations", "patternProperties": { diff --git a/core/deploy/schema/schema.go b/core/deploy/schema/schema.go index 3f8ba12b..2606a32e 100644 --- a/core/deploy/schema/schema.go +++ b/core/deploy/schema/schema.go @@ -14,7 +14,7 @@ func GetSchemaBytes() []byte { // This matches the JSON schema and supports multi-file merging type DeployConfig struct { Configs map[string]any `yaml:"configs" json:"configs"` - NamedDbPools map[string]*DbPoolConfig `yaml:"named-db-pools,omitempty" json:"named-db-pools,omitempty"` + DbPoolManager map[string]*DbPoolConfig `yaml:"dbpool-manager,omitempty" json:"dbpool-manager,omitempty"` MiddlewareDefinitions map[string]*MiddlewareDef `yaml:"middleware-definitions,omitempty" json:"middleware-definitions,omitempty"` ServiceDefinitions map[string]*ServiceDef `yaml:"service-definitions" json:"service-definitions"` RouterDefinitions map[string]*RouterDef `yaml:"router-definitions,omitempty" json:"router-definitions,omitempty"` // Renamed from Routers diff --git a/dbpool_manager/dbpool_crud.go b/dbpool_manager/dbpool_crud.go index baa35dda..e2f2453b 100644 --- a/dbpool_manager/dbpool_crud.go +++ b/dbpool_manager/dbpool_crud.go @@ -40,13 +40,13 @@ func AddDbPool(config DbPoolConfig) error { // Set the pool configuration (upsert: works for both new and existing pools) // This also auto-registers the pool as a lazy service - dpm.SetNamedDbPool(config.Name, config.DSN, config.Schema, config.RlsContext) + dpm.SetDbPoolManager(config.Name, config.DSN, config.Schema, config.RlsContext) // Validate configuration by attempting to get the pool - _, err := dpm.GetNamedDbPool(config.Name) + _, err := dpm.GetDbPoolManager(config.Name) if err != nil { // Rollback on validation failure - dpm.RemoveNamedDbPool(config.Name) + dpm.RemoveDbPoolManager(config.Name) return fmt.Errorf("failed to create pool '%s': %w", config.Name, err) } @@ -75,13 +75,13 @@ func RemoveDbPool(name string) error { } // Check if pool exists - _, _, _, err := dpm.GetNamedDbPoolInfo(name) + _, _, _, err := dpm.GetDbPoolManagerInfo(name) if err != nil { return fmt.Errorf("pool '%s' not found: %w", name, err) } // Remove from manager (also unregisters service automatically) - dpm.RemoveNamedDbPool(name) + dpm.RemoveDbPoolManager(name) logger.LogInfo("✅ Removed DB pool: %s", name) return nil @@ -98,7 +98,7 @@ func GetDbPoolInfo(name string) (*DbPoolConfig, error) { return nil, fmt.Errorf("dbpool-manager service not found") } - dsn, schema, rlsContext, err := dpm.GetNamedDbPoolInfo(name) + dsn, schema, rlsContext, err := dpm.GetDbPoolManagerInfo(name) if err != nil { return nil, fmt.Errorf("pool '%s' not found: %w", name, err) } @@ -119,8 +119,8 @@ func ListDbPools() ([]string, error) { return nil, fmt.Errorf("dbpool-manager service not found") } - // Use GetAllNamedDbPools from DbPoolManager interface - allPools := dpm.GetAllNamedDbPools() + // Use GetAllDbPoolManager from DbPoolManager interface + allPools := dpm.GetAllDbPoolManager() if allPools == nil { return []string{}, nil } @@ -144,7 +144,7 @@ func GetDbPool(name string) (serviceapi.DbPool, error) { return nil, fmt.Errorf("dbpool-manager service not found") } - return dpm.GetNamedDbPool(name) + return dpm.GetDbPoolManager(name) } // AcquireDbConn acquires a connection from a named pool diff --git a/docs/00-introduction/examples/full-framework/01_enterprise_router_service/main.go b/docs/00-introduction/examples/full-framework/01_enterprise_router_service/main.go index 6f60226e..ceb3241a 100644 --- a/docs/00-introduction/examples/full-framework/01_enterprise_router_service/main.go +++ b/docs/00-introduction/examples/full-framework/01_enterprise_router_service/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/primadi/lokstra/common/logger" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" ) @@ -18,7 +19,9 @@ func main() { logger.SetLogLevelFromEnv() - lokstra_registry.LoadConfig("config") + if _, err := loader.LoadConfig("config"); err != nil { + panic(err) + } dsn := lokstra_registry.GetConfig("db_main.dsn", "") schema := lokstra_registry.GetConfig("db_main.schema", "public") diff --git a/docs/00-introduction/examples/full-framework/02-multi-deployment-yaml/main.go b/docs/00-introduction/examples/full-framework/02-multi-deployment-yaml/main.go index 017f5b1e..d18ba109 100644 --- a/docs/00-introduction/examples/full-framework/02-multi-deployment-yaml/main.go +++ b/docs/00-introduction/examples/full-framework/02-multi-deployment-yaml/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/primadi/lokstra/common/logger" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_registry" ) @@ -23,7 +24,7 @@ func main() { registerMiddlewareTypes() // 3. RunServerFromConfig - if err := lokstra_registry.LoadConfig(); err != nil { + if _, err := loader.LoadConfig(); err != nil { logger.LogPanic("❌ Failed to load config:", err) } diff --git a/docs/00-introduction/examples/full-framework/04-external-services/main.go b/docs/00-introduction/examples/full-framework/04-external-services/main.go index be71d71d..348daab5 100644 --- a/docs/00-introduction/examples/full-framework/04-external-services/main.go +++ b/docs/00-introduction/examples/full-framework/04-external-services/main.go @@ -5,6 +5,7 @@ import ( "github.com/primadi/lokstra/common/logger" "github.com/primadi/lokstra/core/deploy" + "github.com/primadi/lokstra/core/deploy/loader" svc "github.com/primadi/lokstra/docs/00-introduction/examples/full-framework/04-external-services/service" "github.com/primadi/lokstra/lokstra_registry" ) @@ -33,7 +34,7 @@ func main() { printStartInfo() - if err := lokstra_registry.LoadConfig(); err != nil { + if _, err := loader.LoadConfig(); err != nil { logger.LogPanic("❌ Failed to load config:", err) } diff --git a/docs/00-introduction/examples/full-framework/06-inline-definitions-example/main.go b/docs/00-introduction/examples/full-framework/06-inline-definitions-example/main.go index 128257dc..d8a6f39f 100644 --- a/docs/00-introduction/examples/full-framework/06-inline-definitions-example/main.go +++ b/docs/00-introduction/examples/full-framework/06-inline-definitions-example/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/primadi/lokstra/common/logger" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_registry" ) @@ -12,7 +13,7 @@ func main() { // Get config path // configPath := filepath.Join("docs", "00-introduction", "examples", "full-framework", "06-inline-definitions-example", "config.yaml") - if err := lokstra_registry.LoadConfig(); err != nil { + if _, err := loader.LoadConfig(); err != nil { logger.LogPanic("❌ Failed to load config:", err) } diff --git a/docs/02-framework-guide/04-config/examples/01-basic-config/main.go b/docs/02-framework-guide/04-config/examples/01-basic-config/main.go index 9adc6504..fb6013fa 100644 --- a/docs/02-framework-guide/04-config/examples/01-basic-config/main.go +++ b/docs/02-framework-guide/04-config/examples/01-basic-config/main.go @@ -3,6 +3,7 @@ package main import ( "log" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/middleware/recovery" @@ -13,7 +14,7 @@ func main() { lokstra_init.Bootstrap() // STEP 1: Load Config - if err := lokstra_registry.LoadConfig("config.yaml"); err != nil { + if _, err := loader.LoadConfig("config.yaml"); err != nil { log.Fatal("Failed to load config:", err) } diff --git a/docs/02-framework-guide/04-config/examples/02-multi-file/main.go b/docs/02-framework-guide/04-config/examples/02-multi-file/main.go index 476f0060..a595484d 100644 --- a/docs/02-framework-guide/04-config/examples/02-multi-file/main.go +++ b/docs/02-framework-guide/04-config/examples/02-multi-file/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/primadi/lokstra/common/logger" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" ) @@ -9,7 +10,7 @@ import ( func main() { lokstra_init.Bootstrap() - if err := lokstra_registry.LoadConfig( + if _, err := loader.LoadConfig( "config/base.yaml", "config/dev.yaml", // or production.yaml for prod ); err != nil { diff --git a/docs/02-framework-guide/04-config/examples/06-handlers/main.go b/docs/02-framework-guide/04-config/examples/06-handlers/main.go index f9abfc85..40fc2b98 100644 --- a/docs/02-framework-guide/04-config/examples/06-handlers/main.go +++ b/docs/02-framework-guide/04-config/examples/06-handlers/main.go @@ -3,6 +3,7 @@ package main import ( "log" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/middleware/recovery" @@ -12,7 +13,7 @@ func main() { lokstra_init.Bootstrap() // STEP 1: Load Config - if err := lokstra_registry.LoadConfig("config.yaml"); err != nil { + if _, err := loader.LoadConfig("config.yaml"); err != nil { log.Fatal("Failed to load config:", err) } diff --git a/docs/02-framework-guide/04-config/examples/07-db-pools/README.md b/docs/02-framework-guide/04-config/examples/07-db-pools/README.md index dd05276c..2890b39c 100644 --- a/docs/02-framework-guide/04-config/examples/07-db-pools/README.md +++ b/docs/02-framework-guide/04-config/examples/07-db-pools/README.md @@ -18,7 +18,7 @@ Demonstrates configuring multiple named database pools with different settings. #### Option 1: Component-Based ```yaml -named-db-pools: +dbpool-manager: main-db: host: "localhost" port: 5432 @@ -35,7 +35,7 @@ named-db-pools: #### Option 2: DSN-Based ```yaml -named-db-pools: +dbpool-manager: analytics-db: dsn: "postgres://user:pass@host:5432/db?sslmode=require" schema: "analytics" @@ -227,7 +227,7 @@ sslmode: "require" # or verify-full ### 4. Environment Variables ```yaml -named-db-pools: +dbpool-manager: main-db: host: "${DB_HOST}" port: 5432 diff --git a/docs/02-framework-guide/04-config/examples/07-db-pools/config.yaml b/docs/02-framework-guide/04-config/examples/07-db-pools/config.yaml index 8a299a6f..52c70106 100644 --- a/docs/02-framework-guide/04-config/examples/07-db-pools/config.yaml +++ b/docs/02-framework-guide/04-config/examples/07-db-pools/config.yaml @@ -6,7 +6,7 @@ configs: name: "DatabaseApp" # Named database pool configurations -named-db-pools: +dbpool-manager: # Main application database main-db: host: "localhost" diff --git a/docs/02-framework-guide/04-config/examples/README.md b/docs/02-framework-guide/04-config/examples/README.md index f528fb8c..718e77bb 100644 --- a/docs/02-framework-guide/04-config/examples/README.md +++ b/docs/02-framework-guide/04-config/examples/README.md @@ -78,7 +78,7 @@ Recommended order: ### Configuration Hierarchy ``` configs # Global config values -named-db-pools # Database pool definitions +dbpool-manager # Database pool definitions middleware-definitions # Middleware instances service-definitions # Service instances router-definitions # Router configurations diff --git a/docs/02-framework-guide/04-config/index.md b/docs/02-framework-guide/04-config/index.md index 6d720374..c0afba44 100644 --- a/docs/02-framework-guide/04-config/index.md +++ b/docs/02-framework-guide/04-config/index.md @@ -92,7 +92,7 @@ configs: dsn: "postgres://localhost/mydb" # Named database pools -named-db-pools: +dbpool-manager: main-db: dsn: "postgres://localhost:5432/mydb" schema: "public" @@ -205,7 +205,7 @@ Reference: `${app.name}`, `${database.host}` ### Named DB Pools ```yaml -named-db-pools: +dbpool-manager: main-db: host: "localhost" port: 5432 @@ -222,7 +222,7 @@ named-db-pools: Or use DSN directly: ```yaml -named-db-pools: +dbpool-manager: main-db: dsn: "postgres://user:pass@localhost:5432/mydb" schema: "public" diff --git a/docs/02-framework-guide/08-database-pools.md b/docs/02-framework-guide/08-database-pools.md index 11080b4f..bf999502 100644 --- a/docs/02-framework-guide/08-database-pools.md +++ b/docs/02-framework-guide/08-database-pools.md @@ -15,7 +15,7 @@ Lokstra provides built-in support for database connection pooling with automatic **config.yaml:** ```yaml -named-db-pools: +dbpool-manager: main-db: dsn: "postgres://user:pass@localhost:5432/mydb?sslmode=disable" min_conns: 2 @@ -48,7 +48,7 @@ func main() { } // 2. Setup DB pools explicitly (if needed) - if err := lokstra.SetupNamedDbPools(); err != nil { + if err := lokstra.SetupDbPoolManager(); err != nil { log.Fatal(err) } @@ -116,7 +116,7 @@ service-definitions: ### Option 1: Direct DSN ```yaml -named-db-pools: +dbpool-manager: mydb: dsn: "postgres://user:pass@localhost:5432/mydb?sslmode=disable" ``` @@ -124,7 +124,7 @@ named-db-pools: ### Option 2: Component-Based (Recommended) ```yaml -named-db-pools: +dbpool-manager: mydb: host: ${DB_HOST:localhost} port: ${DB_PORT:5432} @@ -152,7 +152,7 @@ named-db-pools: ```go // Load config first, setup DB later lokstra_registry.LoadConfig("config.yaml") -lokstra.SetupNamedDbPools() +lokstra.SetupDbPoolManager() ``` ❌ **Bad:** @@ -164,7 +164,7 @@ lokstra_registry.RunServerFromConfig("config.yaml") ### 2. Use Named Pools for Different Purposes ```yaml -named-db-pools: +dbpool-manager: transactional-db: # For OLTP workloads max_conns: 10 @@ -178,7 +178,7 @@ named-db-pools: ### 3. Environment-Specific Configuration ```yaml -named-db-pools: +dbpool-manager: main-db: host: ${DB_HOST:localhost} port: ${DB_PORT:5432} diff --git a/docs/schema/lokstra.schema.json b/docs/schema/lokstra.schema.json index 0f2adb26..e87ed919 100644 --- a/docs/schema/lokstra.schema.json +++ b/docs/schema/lokstra.schema.json @@ -314,7 +314,7 @@ } } }, - "named-db-pools": { + "dbpool-manager": { "type": "object", "description": "Named database pool configurations", "patternProperties": { diff --git a/go.mod b/go.mod index f88006d2..9ebff8e2 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/json-iterator/go v1.1.12 github.com/prometheus/client_golang v1.23.2 github.com/xeipuuv/gojsonschema v1.2.0 - golang.org/x/crypto v0.45.0 + golang.org/x/crypto v0.46.0 ) require ( @@ -30,11 +30,11 @@ require ( github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect go.uber.org/mock v0.6.0 // indirect go.yaml.in/yaml/v2 v2.4.3 // indirect - golang.org/x/net v0.47.0 // indirect - golang.org/x/sync v0.18.0 // indirect - golang.org/x/sys v0.38.0 // indirect - golang.org/x/text v0.31.0 // indirect - google.golang.org/protobuf v1.36.10 // indirect + golang.org/x/net v0.48.0 // indirect + golang.org/x/sync v0.19.0 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/text v0.32.0 // indirect + google.golang.org/protobuf v1.36.11 // indirect ) require ( diff --git a/go.sum b/go.sum index ba38ca3e..007b3efa 100644 --- a/go.sum +++ b/go.sum @@ -91,18 +91,30 @@ go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= +golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU= +golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0= golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= +golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU= +golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY= golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I= golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= +golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= +golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU= +golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY= golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= +google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/lokstra_init/initialize.go b/lokstra_init/initialize.go index ad1c0c11..26a5ced6 100644 --- a/lokstra_init/initialize.go +++ b/lokstra_init/initialize.go @@ -5,6 +5,7 @@ import ( "time" "github.com/primadi/lokstra/common/logger" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/services/sync_config_pg" ) @@ -59,6 +60,7 @@ func BootstrapAndRun(opts ...InitializeOption) error { cfg := &InitializeConfig{ PanicOnConfigError: true, LogLevel: logger.LogLevelInfo, + EnableLoadConfig: true, EnableAnnotation: true, // Auto-detect @RouterService EnableDbPoolManager: false, IsDbPoolAutoSync: false, @@ -109,7 +111,7 @@ func BootstrapAndRunWithConfig(cfg *InitializeConfig) error { // 3. LoadConfig if cfg.EnableLoadConfig { - if err := lokstra_registry.LoadConfig(cfg.ConfigPath...); err != nil { + if _, err := loader.LoadConfig(cfg.ConfigPath...); err != nil { return cfg.returnError(err) } } @@ -128,7 +130,7 @@ func BootstrapAndRunWithConfig(cfg *InitializeConfig) error { if cfg.EnableDbPoolManager { UsePgxDbPoolManager(cfg.IsDbPoolAutoSync) - if err := lokstra_registry.LoadNamedDbPoolsFromConfig(); err != nil { + if err := loader.LoadDbPoolManagerFromConfig(); err != nil { return cfg.returnError(err) } } diff --git a/lokstra_init/migration.go b/lokstra_init/migration.go index 7677bd5e..92ecd82c 100644 --- a/lokstra_init/migration.go +++ b/lokstra_init/migration.go @@ -17,7 +17,7 @@ import ( // MigrationYamlConfig represents the migration.yaml file structure // This file is optional and located in the migrations directory type MigrationYamlConfig struct { - // DbPoolName is the database pool name from config.yaml named-db-pools + // DbPoolName is the database pool name from config.yaml dbpool-manager DbPoolName string `yaml:"dbpool-name"` // SchemaTable is the table name for tracking migrations @@ -40,7 +40,7 @@ type MigrationConfig struct { // Default: "migrations" MigrationsDir string - // DbPoolName is the name of the database pool from named-db-pools + // DbPoolName is the name of the database pool from dbpool-manager // Default: "main-db" // Can be overridden by migration.yaml DbPoolName string @@ -115,7 +115,7 @@ func CheckDbMigration(cfg *MigrationConfig) error { // Get database pool pool, ok := lokstra_registry.GetServiceAny(cfg.DbPoolName) if !ok { - return fmt.Errorf("database pool '%s' not found - check your config.yaml named-db-pools section", cfg.DbPoolName) + return fmt.Errorf("database pool '%s' not found - check your config.yaml dbpool-manager section", cfg.DbPoolName) } dbPool, ok := pool.(serviceapi.DbPool) diff --git a/lokstra_registry/helper.go b/lokstra_registry/helper.go index 3335ef25..ff5e4138 100644 --- a/lokstra_registry/helper.go +++ b/lokstra_registry/helper.go @@ -2,44 +2,8 @@ package lokstra_registry import ( "time" - - "github.com/primadi/lokstra/common/logger" - "github.com/primadi/lokstra/core/deploy/loader" ) -// LoadConfig loads configuration from the specified file path. -// path can be one or more YAML files or folders. -// If no path is provided, it defaults to "config" folder -func LoadConfig(configPaths ...string) error { - if len(configPaths) == 0 { - configPaths = []string{"config"} - } - - // Load config (loads ALL deployments into Global registry) - if _, err := loader.LoadConfig(configPaths...); err != nil { - return err - } - - logger.LogDebug("✅ Config loaded successfully from: %v", configPaths) - return nil -} - -// LoadNamedDbPoolsFromConfig sets up database pools from loaded config. -// Must be called AFTER LoadConfig() if you use named-db-pools in config. -// Call this explicitly only if you need DB pools. -// -// Example: -// -// if err := lokstra_registry.LoadConfig("config.yaml"); err != nil { -// logger.LogPanic(err) -// } -// if err := lokstra_registry.LoadNamedDbPoolsFromConfig(); err != nil { -// logger.LogPanic(err) -// } -func LoadNamedDbPoolsFromConfig() error { - return loader.LoadNamedDbPoolsFromConfig() -} - // RunConfiguredServer initializes and runs the server based on loaded config. // Must be called after LoadConfig() and service/middleware registration. // diff --git a/project_templates/02_app_framework/01_medium_system/main.go b/project_templates/02_app_framework/01_medium_system/main.go index 7432edfa..e0185b6e 100644 --- a/project_templates/02_app_framework/01_medium_system/main.go +++ b/project_templates/02_app_framework/01_medium_system/main.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/primadi/lokstra/common/logger" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_registry" ) @@ -32,7 +33,7 @@ func main() { registerMiddlewareTypes() // 3. Run server from config - if err := lokstra_registry.LoadConfig(); err != nil { + if _, err := loader.LoadConfig(); err != nil { logger.LogPanic("❌ Failed to load config:", err) } diff --git a/project_templates/02_app_framework/02_enterprise_modular/main.go b/project_templates/02_app_framework/02_enterprise_modular/main.go index bf706d14..9dbb4aba 100644 --- a/project_templates/02_app_framework/02_enterprise_modular/main.go +++ b/project_templates/02_app_framework/02_enterprise_modular/main.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/primadi/lokstra/common/logger" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_registry" ) @@ -25,7 +26,7 @@ func main() { // 3. Run server from config folder // Lokstra will automatically merge all YAML files in config/ folder - if err := lokstra_registry.LoadConfig("config"); err != nil { + if _, err := loader.LoadConfig("config"); err != nil { logger.LogPanic("❌ Failed to load config:", err) } diff --git a/project_templates/02_app_framework/03_enterprise_router_service/config/deployment.yaml b/project_templates/02_app_framework/03_enterprise_router_service/config/deployment.yaml index f9fdca44..0a1c67da 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/config/deployment.yaml +++ b/project_templates/02_app_framework/03_enterprise_router_service/config/deployment.yaml @@ -5,7 +5,7 @@ configs: store: order-repository: order-repository -named-db-pools: +dbpool-manager: db_main: dsn: ${GLOBAL_DB_DSN:postgres://postgres:adm1n@localhost:5432/lokstra_db} schema: ${GLOBAL_DB_SCHEMA:lokstra_auth} diff --git a/project_templates/02_app_framework/03_enterprise_router_service/main.go b/project_templates/02_app_framework/03_enterprise_router_service/main.go index 2f8a68d0..884ddbde 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/main.go +++ b/project_templates/02_app_framework/03_enterprise_router_service/main.go @@ -22,7 +22,6 @@ func main() { fmt.Println("╚═══════════════════════════════════════════════╝") fmt.Println("") - registerServiceTypes() registerRouters() registerMiddlewareTypes() diff --git a/project_templates/02_app_framework/03_enterprise_router_service/main_alt.go b/project_templates/02_app_framework/03_enterprise_router_service/main_alt.go deleted file mode 100644 index 804077d5..00000000 --- a/project_templates/02_app_framework/03_enterprise_router_service/main_alt.go +++ /dev/null @@ -1,38 +0,0 @@ -package main - -import ( - "fmt" - - "github.com/primadi/lokstra/common/logger" - "github.com/primadi/lokstra/lokstra_init" - "github.com/primadi/lokstra/lokstra_registry" -) - -func AltMain() { - lokstra_init.Bootstrap() - - fmt.Println("") - fmt.Println("╔═══════════════════════════════════════════════╗") - fmt.Println("║ LOKSTRA ENTERPRISE MODULAR TEMPLATE ║") - fmt.Println("║ Domain-Driven Design with Bounded Contexts ║") - fmt.Println("╚═══════════════════════════════════════════════╝") - fmt.Println("") - - logger.SetLogLevelFromEnv() - - // 1. Register service types from all modules - registerServiceTypes() - - // 2. Register middleware types - registerMiddlewareTypes() - - // 3. Run server from config folder - // Lokstra will automatically merge all YAML files in config/ folder - if err := lokstra_registry.LoadConfig("config"); err != nil { - logger.LogPanic("❌ Failed to load config:", err) - } - - if err := lokstra_registry.RunConfiguredServer(); err != nil { - logger.LogPanic("❌ Failed to run server:", err) - } -} diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application/order_service.go b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application/order_service.go index 1bd0bd58..3db6e919 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application/order_service.go +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application/order_service.go @@ -78,7 +78,3 @@ func (s *OrderServiceImpl) Cancel(p *domain.CancelOrderRequest) error { func (s *OrderServiceImpl) Delete(p *domain.DeleteOrderRequest) error { return s.OrderRepo.Delete(p.ID) } - -func Register() { - // do nothing, just to ensure package is loaded -} diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application/zz_cache.lokstra.json b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application/zz_cache.lokstra.json index df6f6f8c..88cda05e 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application/zz_cache.lokstra.json +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application/zz_cache.lokstra.json @@ -3,15 +3,15 @@ "files": { "order_service.go": { "filename": "order_service.go", - "checksum": "0e9de2b32a33d7477e9d083b5474ef63469da374814b2ba6c6e0a0b5f67eee47", + "checksum": "b19aa04bf05b27274bfff208e58dee28ac1eb025e6fc6f001ff37981359b8086", "annotations": 9, - "last_scan": "2025-12-10T01:55:27.3979337+07:00", + "last_scan": "2025-12-16T11:43:09.5059915+07:00", "generated": [ "zz_generated.lokstra.go" ], - "generated_mod_time": "2025-12-10T01:55:27.3979337+07:00" + "generated_mod_time": "2025-12-16T11:43:09.5059915+07:00" } }, - "updated_at": "2025-12-12T15:39:36.8536949+07:00", + "updated_at": "2025-12-16T11:43:21.5925431+07:00", "generated_checksum": "3ae8ac2a982d5877f5c7da1f9297cf5364ea09253728c7980f9c8cc42f1415b0" } \ No newline at end of file diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/order_repository.go b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/order_repository.go index 8ee7d1b6..3b376144 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/order_repository.go +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/order_repository.go @@ -9,6 +9,7 @@ import ( ) // OrderRepositoryImpl implements domain.OrderRepository with in-memory storage +// @Service "order-repository" type OrderRepositoryImpl struct { mu sync.RWMutex orders map[int]*domain.Order @@ -20,12 +21,10 @@ type OrderRepositoryImpl struct { var _ domain.OrderRepository = (*OrderRepositoryImpl)(nil) // NewOrderRepository creates a new in-memory order repository with seed data -func NewOrderRepository() *OrderRepositoryImpl { - repo := &OrderRepositoryImpl{ - orders: make(map[int]*domain.Order), - byUserID: make(map[int][]*domain.Order), - nextID: 1, - } +func (r *OrderRepositoryImpl) Init() error { + r.orders = make(map[int]*domain.Order) + r.byUserID = make(map[int][]*domain.Order) + r.nextID = 1 // Seed data seedOrders := []*domain.Order{ @@ -35,10 +34,10 @@ func NewOrderRepository() *OrderRepositoryImpl { } for _, o := range seedOrders { - repo.Create(o) + r.Create(o) } - return repo + return nil } // GetByID retrieves an order by ID @@ -143,8 +142,3 @@ func (r *OrderRepositoryImpl) Delete(id int) error { return nil } - -// OrderRepositoryFactory creates a new OrderRepositoryImpl instance -func OrderRepositoryFactory(deps map[string]any, config map[string]any) any { - return NewOrderRepository() -} diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/zz_cache.lokstra.json b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/zz_cache.lokstra.json new file mode 100644 index 00000000..b5ba7879 --- /dev/null +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/zz_cache.lokstra.json @@ -0,0 +1,17 @@ +{ + "version": 1, + "files": { + "order_repository.go": { + "filename": "order_repository.go", + "checksum": "98ea32dc130768aedeeedbac9af3c95d66ff0b3ee86bff7ace461ffca596ef79", + "annotations": 1, + "last_scan": "2025-12-16T11:43:09.5004861+07:00", + "generated": [ + "zz_generated.lokstra.go" + ], + "generated_mod_time": "2025-12-16T11:43:09.5004861+07:00" + } + }, + "updated_at": "2025-12-16T11:43:21.5945311+07:00", + "generated_checksum": "16bf8b62121710a85ab8925d12f8fc61adf16b6bceb54ced37056b178b9482ef" +} \ No newline at end of file diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/zz_generated.lokstra.go b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/zz_generated.lokstra.go new file mode 100644 index 00000000..5ed35515 --- /dev/null +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository/zz_generated.lokstra.go @@ -0,0 +1,38 @@ +// AUTO-GENERATED CODE - DO NOT EDIT +// Generated by lokstra-annotation from annotations in this folder +// Annotations: @RouterService, @Service, @Inject, @InjectCfgValue, @Route + +package repository + +import ( + "github.com/primadi/lokstra/lokstra_registry" +) + +// Auto-register on package import +func init() { + RegisterOrderRepositoryImpl() +} + +// ============================================================ +// FILE: order_repository.go +// ============================================================ + +// RegisterOrderRepositoryImpl registers the order-repository with the registry +// Auto-generated from annotations: +// - @Service name="order-repository" +func RegisterOrderRepositoryImpl() { + lokstra_registry.RegisterLazyService("order-repository", func(deps map[string]any, cfg map[string]any) any { + svc := &OrderRepositoryImpl{ + } + + // Call Init() for post-initialization + if err := svc.Init(); err != nil { + panic("failed to initialize order-repository: " + err.Error()) + } + + return svc + }, map[string]any{ + }) +} + + diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/register.go b/project_templates/02_app_framework/03_enterprise_router_service/modules/order/register.go deleted file mode 100644 index d9221f0a..00000000 --- a/project_templates/02_app_framework/03_enterprise_router_service/modules/order/register.go +++ /dev/null @@ -1,19 +0,0 @@ -package order - -import ( - "github.com/primadi/lokstra/lokstra_registry" - "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application" - "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository" -) - -// Register registers all order module service types -// This is owned by the module and defines intrinsic routing behavior -func Register() { - // Register order repository (infrastructure - local only) - lokstra_registry.RegisterServiceType("order-repository-factory", - repository.OrderRepositoryFactory) - - lokstra_registry.RegisterLazyService("order-repository", "order-repository-factory", nil) - - application.Register() -} diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application/user_service.go b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application/user_service.go index 48e95d8e..53babfa0 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application/user_service.go +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application/user_service.go @@ -71,7 +71,3 @@ func (s *UserServiceImpl) Activate(p *domain.ActivateUserRequest) error { func (s *UserServiceImpl) Delete(p *domain.DeleteUserRequest) error { return s.UserRepo.Delete(p.ID) } - -func Register() { - // do nothing, just to make sure the package is loaded -} diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application/zz_cache.lokstra.json b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application/zz_cache.lokstra.json index 63956bf2..cbb050d2 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application/zz_cache.lokstra.json +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application/zz_cache.lokstra.json @@ -3,15 +3,15 @@ "files": { "user_service.go": { "filename": "user_service.go", - "checksum": "8a406a9a57f5db224e7f8260fc3f1fdc21ab33f73d6e0224b60df10810138fc6", + "checksum": "2f6340c9382716a7ec0428b8f6db6a0d40dddf3c5372549b4ca5b188917dca5d", "annotations": 9, - "last_scan": "2025-12-10T03:50:06.636111+07:00", + "last_scan": "2025-12-16T11:43:09.5087265+07:00", "generated": [ "zz_generated.lokstra.go" ], - "generated_mod_time": "2025-12-10T03:50:06.636111+07:00" + "generated_mod_time": "2025-12-16T11:43:09.5087265+07:00" } }, - "updated_at": "2025-12-12T15:39:36.8554716+07:00", + "updated_at": "2025-12-16T11:43:21.5925431+07:00", "generated_checksum": "f1d4037b46a04ef378b4d985efb148c26f695e3f6db1601bee944b4992502afb" } \ No newline at end of file diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/user_repository.go b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/user_repository.go index b1fe6034..6aacf86b 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/user_repository.go +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/user_repository.go @@ -8,6 +8,7 @@ import ( ) // UserRepositoryImpl implements domain.UserRepository with in-memory storage +// @Service "user-repository" type UserRepositoryImpl struct { mu sync.RWMutex users map[int]*domain.User @@ -18,13 +19,10 @@ type UserRepositoryImpl struct { // Ensure implementation var _ domain.UserRepository = (*UserRepositoryImpl)(nil) -// NewUserRepository creates a new in-memory user repository with seed data -func NewUserRepository() *UserRepositoryImpl { - repo := &UserRepositoryImpl{ - users: make(map[int]*domain.User), - byEmail: make(map[string]*domain.User), - nextID: 1, - } +func (r *UserRepositoryImpl) Init() error { + r.users = make(map[int]*domain.User) + r.byEmail = make(map[string]*domain.User) + r.nextID = 1 // Seed data seedUsers := []*domain.User{ @@ -34,10 +32,10 @@ func NewUserRepository() *UserRepositoryImpl { } for _, u := range seedUsers { - repo.Create(u) + r.Create(u) } - return repo + return nil } // GetByID retrieves a user by ID @@ -130,8 +128,3 @@ func (r *UserRepositoryImpl) Delete(id int) error { delete(r.byEmail, user.Email) return nil } - -// UserRepositoryFactory creates a new UserRepositoryImpl instance -func UserRepositoryFactory(deps map[string]any, config map[string]any) any { - return NewUserRepository() -} diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/zz_cache.lokstra.json b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/zz_cache.lokstra.json new file mode 100644 index 00000000..e97118a2 --- /dev/null +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/zz_cache.lokstra.json @@ -0,0 +1,17 @@ +{ + "version": 1, + "files": { + "user_repository.go": { + "filename": "user_repository.go", + "checksum": "7dafad18a4f0c697959f64464c62083d87606cfd720531f643305e6d97a9fddf", + "annotations": 1, + "last_scan": "2025-12-16T11:43:09.5032337+07:00", + "generated": [ + "zz_generated.lokstra.go" + ], + "generated_mod_time": "2025-12-16T11:43:09.5032337+07:00" + } + }, + "updated_at": "2025-12-16T11:43:21.5931069+07:00", + "generated_checksum": "84e08cd520f9a6f6ccefb1c77c8d82b2b5cf5481eef82a869c454fbf23cf5208" +} \ No newline at end of file diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/zz_generated.lokstra.go b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/zz_generated.lokstra.go new file mode 100644 index 00000000..f71e931e --- /dev/null +++ b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository/zz_generated.lokstra.go @@ -0,0 +1,38 @@ +// AUTO-GENERATED CODE - DO NOT EDIT +// Generated by lokstra-annotation from annotations in this folder +// Annotations: @RouterService, @Service, @Inject, @InjectCfgValue, @Route + +package repository + +import ( + "github.com/primadi/lokstra/lokstra_registry" +) + +// Auto-register on package import +func init() { + RegisterUserRepositoryImpl() +} + +// ============================================================ +// FILE: user_repository.go +// ============================================================ + +// RegisterUserRepositoryImpl registers the user-repository with the registry +// Auto-generated from annotations: +// - @Service name="user-repository" +func RegisterUserRepositoryImpl() { + lokstra_registry.RegisterLazyService("user-repository", func(deps map[string]any, cfg map[string]any) any { + svc := &UserRepositoryImpl{ + } + + // Call Init() for post-initialization + if err := svc.Init(); err != nil { + panic("failed to initialize user-repository: " + err.Error()) + } + + return svc + }, map[string]any{ + }) +} + + diff --git a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/register.go b/project_templates/02_app_framework/03_enterprise_router_service/modules/user/register.go deleted file mode 100644 index a86fa418..00000000 --- a/project_templates/02_app_framework/03_enterprise_router_service/modules/user/register.go +++ /dev/null @@ -1,19 +0,0 @@ -package user - -import ( - "github.com/primadi/lokstra/lokstra_registry" - "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application" - "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository" -) - -// Register registers all user module service types -// This is owned by the module and defines intrinsic routing behavior -func Register() { - // Register user repository (infrastructure - local only) - lokstra_registry.RegisterServiceType("user-repository-factory", - repository.UserRepositoryFactory) - - lokstra_registry.RegisterLazyService("user-repository", "user-repository-factory", nil) - - application.Register() -} diff --git a/project_templates/02_app_framework/03_enterprise_router_service/register.go b/project_templates/02_app_framework/03_enterprise_router_service/register.go index 8073d2f1..aa1822b8 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/register.go +++ b/project_templates/02_app_framework/03_enterprise_router_service/register.go @@ -6,17 +6,8 @@ import ( "github.com/primadi/lokstra/core/request" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/middleware/recovery" - - "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/order" - "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/user" ) -func registerServiceTypes() { - // Register modules (each module owns its service type registration) - user.Register() - order.Register() -} - func registerRouters() { // Register manual routers (not generated from @RouterService) healthRouter := NewHealthRouter() diff --git a/project_templates/02_app_framework/03_enterprise_router_service/zz_lokstra_imports.go b/project_templates/02_app_framework/03_enterprise_router_service/zz_lokstra_imports.go index 988ee68c..f23b8dc3 100644 --- a/project_templates/02_app_framework/03_enterprise_router_service/zz_lokstra_imports.go +++ b/project_templates/02_app_framework/03_enterprise_router_service/zz_lokstra_imports.go @@ -6,5 +6,7 @@ package main import ( _ "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/order/application" + _ "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/order/infrastructure/repository" _ "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/user/application" + _ "github.com/primadi/lokstra/project_templates/02_app_framework/03_enterprise_router_service/modules/user/infrastructure/repository" ) diff --git a/project_templates/02_app_framework/04_sync_config/config/config.yaml b/project_templates/02_app_framework/04_sync_config/config/config.yaml index 7e46c917..30a6164f 100644 --- a/project_templates/02_app_framework/04_sync_config/config/config.yaml +++ b/project_templates/02_app_framework/04_sync_config/config/config.yaml @@ -1,6 +1,6 @@ # yaml-language-server: $schema=https://primadi.github.io/lokstra/schema/lokstra.schema.json -named-db-pools: +dbpool-manager: db_main: dsn: ${GLOBAL_DB_DSN:postgres://postgres:adm1n@localhost:5432/lokstra_db} schema: ${GLOBAL_DB_SCHEMA:lokstra_auth} diff --git a/project_templates/02_app_framework/test/main.go b/project_templates/02_app_framework/test/main.go index 28b654dd..f29c4d54 100644 --- a/project_templates/02_app_framework/test/main.go +++ b/project_templates/02_app_framework/test/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/primadi/lokstra" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/syncmap" @@ -12,7 +13,9 @@ func main() { lokstra_init.Bootstrap() // 2. Load application config - lokstra_registry.LoadConfig("config.yaml") + if _, err := loader.LoadConfig("config.yaml"); err != nil { + panic(err) + } // 3. Register routers registerRouters() diff --git a/serviceapi/dbpool_manager.go b/serviceapi/dbpool_manager.go index 3e49f9d5..96056f16 100644 --- a/serviceapi/dbpool_manager.go +++ b/serviceapi/dbpool_manager.go @@ -13,7 +13,7 @@ type DbPoolInfo struct { type DbPoolManager interface { // Get all named DbPools - GetAllNamedDbPools() map[string]*DbPoolInfo + GetAllDbPoolManager() map[string]*DbPoolInfo // get or create DbPool for the given dsn GetDbPool(dsn, schema string, rlsContext map[string]string) (DbPool, error) @@ -28,13 +28,13 @@ type DbPoolManager interface { //---------------------------------------- // set name for the given dsn, schema, and rlsContext - SetNamedDbPool(name string, dsn string, schema string, rlsContext map[string]string) + SetDbPoolManager(name string, dsn string, schema string, rlsContext map[string]string) // get dsn, schema, rlsContext for the given name - GetNamedDbPoolInfo(name string) (string, string, map[string]string, error) + GetDbPoolManagerInfo(name string) (string, string, map[string]string, error) // get DbPool for the given name - GetNamedDbPool(name string) (DbPool, error) + GetDbPoolManager(name string) (DbPool, error) // remove name mapping - RemoveNamedDbPool(name string) + RemoveDbPoolManager(name string) // acquire connection for the given name AcquireNamedConn(ctx context.Context, name string) (DbConn, error) diff --git a/services/dbpool_manager/dbpool_manager.go b/services/dbpool_manager/dbpool_manager.go index d79a62bf..564502ba 100644 --- a/services/dbpool_manager/dbpool_manager.go +++ b/services/dbpool_manager/dbpool_manager.go @@ -74,8 +74,8 @@ func (p *DbPoolManager) GetDbPool(dsn string, schema string, rlsContext map[stri return newPool, nil } -// GetNamedDbPool implements serviceapi.DbPoolManager. -func (p *DbPoolManager) GetNamedDbPool(name string) (serviceapi.DbPool, error) { +// GetDbPoolManager implements serviceapi.DbPoolManager. +func (p *DbPoolManager) GetDbPoolManager(name string) (serviceapi.DbPool, error) { p.mu.RLock() dbPoolInfo, ok := p.namedPools[name] p.mu.RUnlock() @@ -85,8 +85,8 @@ func (p *DbPoolManager) GetNamedDbPool(name string) (serviceapi.DbPool, error) { return p.GetDbPool(dbPoolInfo.Dsn, dbPoolInfo.Schema, dbPoolInfo.RlsContext) } -// GetNamedDbPoolInfo implements serviceapi.DbPoolManager. -func (p *DbPoolManager) GetNamedDbPoolInfo(name string) (string, string, map[string]string, error) { +// GetDbPoolManagerInfo implements serviceapi.DbPoolManager. +func (p *DbPoolManager) GetDbPoolManagerInfo(name string) (string, string, map[string]string, error) { p.mu.RLock() dbPoolInfo, ok := p.namedPools[name] p.mu.RUnlock() @@ -96,8 +96,8 @@ func (p *DbPoolManager) GetNamedDbPoolInfo(name string) (string, string, map[str return dbPoolInfo.Dsn, dbPoolInfo.Schema, dbPoolInfo.RlsContext, nil } -// RemoveNamedDbPool implements serviceapi.DbPoolManager. -func (p *DbPoolManager) RemoveNamedDbPool(name string) { +// RemoveDbPoolManager implements serviceapi.DbPoolManager. +func (p *DbPoolManager) RemoveDbPoolManager(name string) { p.mu.Lock() delete(p.namedPools, name) p.mu.Unlock() @@ -108,8 +108,8 @@ func (p *DbPoolManager) RemoveNamedDbPool(name string) { } } -// SetNamedDbPool implements serviceapi.DbPoolManager. -func (p *DbPoolManager) SetNamedDbPool(name string, dsn string, schema string, rlsContext map[string]string) { +// SetDbPoolManager implements serviceapi.DbPoolManager. +func (p *DbPoolManager) SetDbPoolManager(name string, dsn string, schema string, rlsContext map[string]string) { p.mu.Lock() defer p.mu.Unlock() p.namedPools[name] = &serviceapi.DbPoolInfo{ @@ -122,7 +122,7 @@ func (p *DbPoolManager) SetNamedDbPool(name string, dsn string, schema string, r // This makes pools accessible via lokstra_registry.GetService[DbPool](name) if registry := getGlobalRegistry(); registry != nil { registry.RegisterLazyService(name, func() any { - pool, _ := p.GetNamedDbPool(name) + pool, _ := p.GetDbPoolManager(name) return pool }, nil) } @@ -140,7 +140,7 @@ func (p *DbPoolManager) Shutdown() error { return nil } -func (p *DbPoolManager) GetAllNamedDbPools() map[string]*serviceapi.DbPoolInfo { +func (p *DbPoolManager) GetAllDbPoolManager() map[string]*serviceapi.DbPoolInfo { p.mu.RLock() defer p.mu.RUnlock() result := make(map[string]*serviceapi.DbPoolInfo) diff --git a/services/dbpool_manager/sync_pool_manager.go b/services/dbpool_manager/sync_pool_manager.go index 75fd45ef..7ea55b37 100644 --- a/services/dbpool_manager/sync_pool_manager.go +++ b/services/dbpool_manager/sync_pool_manager.go @@ -85,8 +85,8 @@ func (p *SyncDbPoolManager) GetDbPool(dsn string, schema string, rlsContext map[ return newPool, nil } -// GetNamedDbPool implements serviceapi.DbPoolManager. -func (p *SyncDbPoolManager) GetNamedDbPool(name string) (serviceapi.DbPool, error) { +// GetDbPoolManager implements serviceapi.DbPoolManager. +func (p *SyncDbPoolManager) GetDbPoolManager(name string) (serviceapi.DbPool, error) { p.ensureSyncMapInitialized() dbPoolInfo, ok := p.namedPools.Load(name) if !ok { @@ -95,8 +95,8 @@ func (p *SyncDbPoolManager) GetNamedDbPool(name string) (serviceapi.DbPool, erro return p.GetDbPool(dbPoolInfo.Dsn, dbPoolInfo.Schema, dbPoolInfo.RlsContext) } -// GetNamedDbPoolInfo implements serviceapi.DbPoolManager. -func (p *SyncDbPoolManager) GetNamedDbPoolInfo(name string) (string, string, map[string]string, error) { +// GetDbPoolManagerInfo implements serviceapi.DbPoolManager. +func (p *SyncDbPoolManager) GetDbPoolManagerInfo(name string) (string, string, map[string]string, error) { p.ensureSyncMapInitialized() dbPoolInfo, ok := p.namedPools.Load(name) if !ok { @@ -105,8 +105,8 @@ func (p *SyncDbPoolManager) GetNamedDbPoolInfo(name string) (string, string, map return dbPoolInfo.Dsn, dbPoolInfo.Schema, dbPoolInfo.RlsContext, nil } -// RemoveNamedDbPool implements serviceapi.DbPoolManager. -func (p *SyncDbPoolManager) RemoveNamedDbPool(name string) { +// RemoveDbPoolManager implements serviceapi.DbPoolManager. +func (p *SyncDbPoolManager) RemoveDbPoolManager(name string) { p.ensureSyncMapInitialized() p.namedPools.Delete(context.Background(), name) @@ -116,8 +116,8 @@ func (p *SyncDbPoolManager) RemoveNamedDbPool(name string) { } } -// SetNamedDbPool implements serviceapi.DbPoolManager. -func (p *SyncDbPoolManager) SetNamedDbPool(name string, dsn string, schema string, rlsContext map[string]string) { +// SetDbPoolManager implements serviceapi.DbPoolManager. +func (p *SyncDbPoolManager) SetDbPoolManager(name string, dsn string, schema string, rlsContext map[string]string) { p.ensureSyncMapInitialized() p.namedPools.Store(name, &serviceapi.DbPoolInfo{ Dsn: dsn, @@ -129,13 +129,13 @@ func (p *SyncDbPoolManager) SetNamedDbPool(name string, dsn string, schema strin // This makes pools accessible via lokstra_registry.GetService[DbPool](name) if registry := getGlobalRegistry(); registry != nil { registry.RegisterLazyService(name, func() any { - pool, _ := p.GetNamedDbPool(name) + pool, _ := p.GetDbPoolManager(name) return pool }, nil) } } -func (p *SyncDbPoolManager) GetAllNamedDbPools() map[string]*serviceapi.DbPoolInfo { +func (p *SyncDbPoolManager) GetAllDbPoolManager() map[string]*serviceapi.DbPoolInfo { p.ensureSyncMapInitialized() all, err := p.namedPools.All(context.Background()) if err != nil { diff --git a/services/email_smtp/example/main.go b/services/email_smtp/example/main.go index bfda0303..81a597f5 100644 --- a/services/email_smtp/example/main.go +++ b/services/email_smtp/example/main.go @@ -9,6 +9,7 @@ import ( "github.com/primadi/lokstra" "github.com/primadi/lokstra/common/logger" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/services/email_smtp" @@ -32,7 +33,7 @@ func main() { fmt.Println("===========================================") // Load config and run server (auto-registers services from deployments) - if err := lokstra_registry.LoadConfig("configs"); err != nil { + if _, err := loader.LoadConfig("configs"); err != nil { logger.LogPanic(err.Error()) } diff --git a/services/sync_config_pg/config_test.yaml b/services/sync_config_pg/config_test.yaml index da6d1ad7..ee1a8d6c 100644 --- a/services/sync_config_pg/config_test.yaml +++ b/services/sync_config_pg/config_test.yaml @@ -1,6 +1,6 @@ # yaml-language-server: $schema=https://primadi.github.io/lokstra/schema/lokstra.schema.json -named-db-pools: +dbpool-manager: db_main: dsn: ${GLOBAL_DB_DSN:postgres://postgres:adm1n@localhost:5432/lokstra_db} schema: ${GLOBAL_DB_SCHEMA:lokstra_auth} \ No newline at end of file diff --git a/services/sync_config_pg/module.go b/services/sync_config_pg/module.go index 74c61719..cd45e74f 100644 --- a/services/sync_config_pg/module.go +++ b/services/sync_config_pg/module.go @@ -63,7 +63,7 @@ func getDsnAndSchema(cfg *Config) (string, string) { panic("sync_config_pg: deploy config not found") } - poolConfig, ok := deployConfig.NamedDbPools[cfg.DbPoolName] + poolConfig, ok := deployConfig.DbPoolManager[cfg.DbPoolName] if !ok { panic(fmt.Sprintf("sync_config_pg: named pool '%s' not found in config", cfg.DbPoolName)) } diff --git a/services/sync_config_pg/module_test.go b/services/sync_config_pg/module_test.go index 53b9c958..91f0c7cd 100644 --- a/services/sync_config_pg/module_test.go +++ b/services/sync_config_pg/module_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/primadi/lokstra/lokstra_registry" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/services/sync_config_pg" ) @@ -14,7 +14,7 @@ var once sync.Once func loadConfig(t *testing.T) { once.Do(func() { - if err := lokstra_registry.LoadConfig("config_test.yaml"); err != nil { + if _, err := loader.LoadConfig("config_test.yaml"); err != nil { t.Fatalf("Failed to load config: %v", err) } }) diff --git a/services/sync_config_pg/test/config.yaml b/services/sync_config_pg/test/config.yaml index 7854b1b7..ef61c6f0 100644 --- a/services/sync_config_pg/test/config.yaml +++ b/services/sync_config_pg/test/config.yaml @@ -7,7 +7,7 @@ configs: # heartbeat_interval: ${DBPOOL_MANAGER_HEARTBEAT_INTERVAL:5} # in minutes # reconnect_interval: ${DBPOOL_MANAGER_RECONNECT_INTERVAL:5} # in seconds -named-db-pools: +dbpool-manager: db_main: dsn: ${GLOBAL_DB_DSN:postgres://postgres:adm1n@localhost:5432/lokstra_db} schema: ${GLOBAL_DB_SCHEMA:lokstra_auth} diff --git a/services/sync_config_pg/test/main.go b/services/sync_config_pg/test/main.go index 6c801e95..59cd067a 100644 --- a/services/sync_config_pg/test/main.go +++ b/services/sync_config_pg/test/main.go @@ -4,6 +4,7 @@ import ( "time" "github.com/primadi/lokstra" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/services/sync_config_pg" @@ -15,11 +16,15 @@ func main() { lokstra_init.Bootstrap() // 2. Load application config - lokstra_registry.LoadConfig("config.yaml") + if _, err := loader.LoadConfig("config.yaml"); err != nil { + panic(err) + } lokstra_init.UsePgxDbPoolManager(true) sync_config_pg.Register("db_main", 5*time.Minute, 5*time.Second) - lokstra_registry.LoadNamedDbPoolsFromConfig() + if err := loader.LoadDbPoolManagerFromConfig(); err != nil { + panic(err) + } // 3. Register routers registerRouters() diff --git a/syncmap/syncmap_test.go b/syncmap/syncmap_test.go index 0efe0259..d16b9906 100644 --- a/syncmap/syncmap_test.go +++ b/syncmap/syncmap_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/primadi/lokstra/lokstra_registry" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/syncmap" ) @@ -15,7 +15,7 @@ var once sync.Once func loadConfig(t *testing.T) { once.Do(func() { - if err := lokstra_registry.LoadConfig("../services/sync_config_pg/config_test.yaml"); err != nil { + if _, err := loader.LoadConfig("../services/sync_config_pg/config_test.yaml"); err != nil { t.Fatalf("Failed to load config: %v", err) } }) diff --git a/tools/migration_runner/README.md b/tools/migration_runner/README.md index eeeae81d..bf442c67 100644 --- a/tools/migration_runner/README.md +++ b/tools/migration_runner/README.md @@ -9,7 +9,7 @@ Simple database migration tool for Lokstra framework. - ✅ Supports multiple named databases - ✅ Idempotent (safe to run multiple times) - ✅ Transaction support per migration -- ✅ Integrates with Lokstra's named-db-pools +- ✅ Integrates with Lokstra's dbpool-manager - ✅ **Auto-generate migration files** with `create` command - ✅ **Conflict detection** - prevents version collisions - ✅ **Multiple statements** per file (tables, indexes, views, procedures) @@ -155,7 +155,7 @@ DROP TABLE IF EXISTS users; ### config.yaml ```yaml -named-db-pools: +dbpool-manager: main-db: host: localhost port: 5432 @@ -179,7 +179,7 @@ import ( func main() { lokstra.Bootstrap() - // Load config (auto-discovers named-db-pools) + // Load config (auto-discovers dbpool-manager) lokstra_registry.LoadConfigFromFolder("config") // Run migrations before starting server diff --git a/tools/migration_runner/YAML_CONFIG_GUIDE.md b/tools/migration_runner/YAML_CONFIG_GUIDE.md index a38ee3be..30cd09de 100644 --- a/tools/migration_runner/YAML_CONFIG_GUIDE.md +++ b/tools/migration_runner/YAML_CONFIG_GUIDE.md @@ -32,7 +32,7 @@ migrations/ Each migration folder can have a `migration.yaml` file to configure database-specific settings: ```yaml -# Database pool name from config.yaml named-db-pools +# Database pool name from config.yaml dbpool-manager dbpool-name: main-db # Schema migrations tracking table diff --git a/tools/migration_runner/example/README.md b/tools/migration_runner/example/README.md index 68ebdab0..ce923400 100644 --- a/tools/migration_runner/example/README.md +++ b/tools/migration_runner/example/README.md @@ -139,7 +139,7 @@ func main() { - Solution 2: Manually remove from database: `DELETE FROM schema_migrations WHERE version = XXX` **Error: "Database pool 'main-db' not found"** -- Check that `named-db-pools.main-db` is defined in your config.yaml +- Check that `dbpool-manager.main-db` is defined in your config.yaml - Make sure you imported `_ "github.com/primadi/lokstra/services/dbpool_manager"` **Error: "Migrations directory not found"** diff --git a/tools/migration_runner/example/config/config.yaml b/tools/migration_runner/example/config/config.yaml index eef32f8a..e31042e8 100644 --- a/tools/migration_runner/example/config/config.yaml +++ b/tools/migration_runner/example/config/config.yaml @@ -3,7 +3,7 @@ configs: name: "Migration Example" version: "1.0.0" -named-db-pools: +dbpool-manager: main-db: host: localhost port: 5432 diff --git a/tools/migration_runner/example/example_multi_db.go b/tools/migration_runner/example/example_multi_db.go index 217b931e..17cb1f3c 100644 --- a/tools/migration_runner/example/example_multi_db.go +++ b/tools/migration_runner/example/example_multi_db.go @@ -4,6 +4,7 @@ import ( "log" "time" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/services/sync_config_pg" @@ -16,14 +17,16 @@ func main() { lokstra_init.Bootstrap() // load database and other configurations - if err := lokstra_registry.LoadConfig("config"); err != nil { + if _, err := loader.LoadConfig("config"); err != nil { log.Fatalf("Failed to load config: %v", err) } lokstra_init.UsePgxDbPoolManager(true) sync_config_pg.Register("db_main", 5*time.Minute, 5*time.Second) - lokstra_registry.LoadNamedDbPoolsFromConfig() + if err := loader.LoadDbPoolManagerFromConfig(); err != nil { + log.Fatalf("Failed to load named DB pools: %v", err) + } // OPTION 1: Auto-scan all migration folders (RECOMMENDED) // Scans multi_db/ for subdirectories, runs them in alphabetical order diff --git a/tools/migration_runner/example/example_with_lokstra.go b/tools/migration_runner/example/example_with_lokstra.go index 6f11477a..4629a76d 100644 --- a/tools/migration_runner/example/example_with_lokstra.go +++ b/tools/migration_runner/example/example_with_lokstra.go @@ -33,7 +33,7 @@ func ExampleUsage() { // Option 3: Custom database pool err = lokstra_init.CheckDbMigration(&lokstra_init.MigrationConfig{ MigrationsDir: "db/migrations", - DbPoolName: "analytics-db", // from config.yaml named-db-pools + DbPoolName: "analytics-db", // from config.yaml dbpool-manager }) if err != nil { log.Fatalf("Migration failed: %v", err) diff --git a/tools/migration_runner/example/main.go b/tools/migration_runner/example/main.go index 996ed033..3f4cb043 100644 --- a/tools/migration_runner/example/main.go +++ b/tools/migration_runner/example/main.go @@ -7,6 +7,7 @@ import ( "log" "os" + "github.com/primadi/lokstra/core/deploy/loader" "github.com/primadi/lokstra/lokstra_init" "github.com/primadi/lokstra/lokstra_registry" "github.com/primadi/lokstra/serviceapi" @@ -41,12 +42,14 @@ func MainTest() { // Bootstrap and load config for other commands lokstra_init.Bootstrap() - lokstra_registry.LoadConfig("config") + if _, err := loader.LoadConfig("config"); err != nil { + log.Fatalf("Failed to load config: %v", err) + } // Get database pool pool, ok := lokstra_registry.GetServiceAny(*dbName) if !ok { - log.Fatalf("❌ Database pool '%s' not found. Check your config.yaml named-db-pools section", *dbName) + log.Fatalf("❌ Database pool '%s' not found. Check your config.yaml dbpool-manager section", *dbName) } dbPool, ok := pool.(serviceapi.DbPool) diff --git a/tools/migration_runner/example/migration.yaml b/tools/migration_runner/example/migration.yaml index 5ea73f1c..f8f9e6fc 100644 --- a/tools/migration_runner/example/migration.yaml +++ b/tools/migration_runner/example/migration.yaml @@ -4,7 +4,7 @@ # This file allows you to configure migration behavior per database pool # Useful for multi-database systems (tenant-db, ledger-db, analytics-db, etc) -# Database pool name from config.yaml named-db-pools section +# Database pool name from config.yaml dbpool-manager section # If not specified, defaults to "main-db" dbpool-name: main-db