fix: call config.MustInit() before config.Load() so Viper reads env vars
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Without MustInit(), viper.AutomaticEnv() is never called, so Viper cannot read environment variables injected by K8s secrets (envFrom). This caused DATABASE_URL to always appear empty in deployed services, forcing them into standalone/in-memory mode even when a database was provisioned. os.Getenv() calls like JWT_SECRET worked fine (direct syscall). Viper-backed reads like DATABASE_URL did not (require AutomaticEnv). Added pkgconfig.MustInit() call at the top of main() in both the service component template and the full-monorepo example-api. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4d9203eddc
commit
ad1f19739d
@ -24,6 +24,7 @@ import (
|
|||||||
emailpkg "{{GO_MODULE}}/pkg/email"
|
emailpkg "{{GO_MODULE}}/pkg/email"
|
||||||
"{{GO_MODULE}}/pkg/notify"
|
"{{GO_MODULE}}/pkg/notify"
|
||||||
"{{GO_MODULE}}/pkg/queue"
|
"{{GO_MODULE}}/pkg/queue"
|
||||||
|
pkgconfig "{{GO_MODULE}}/pkg/config"
|
||||||
"{{GO_MODULE}}/pkg/realtime"
|
"{{GO_MODULE}}/pkg/realtime"
|
||||||
"{{GO_MODULE}}/pkg/storage"
|
"{{GO_MODULE}}/pkg/storage"
|
||||||
"{{GO_MODULE}}/pkg/textgen"
|
"{{GO_MODULE}}/pkg/textgen"
|
||||||
@ -58,6 +59,13 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize viper with AutomaticEnv so Viper reads env vars injected by
|
||||||
|
// the platform (K8s secrets, envFrom). Must happen before any config reads.
|
||||||
|
pkgconfig.MustInit(pkgconfig.Options{
|
||||||
|
AppName: "{{COMPONENT_NAME}}",
|
||||||
|
DefaultPort: {{PORT}},
|
||||||
|
})
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
cfg := config.Load()
|
cfg := config.Load()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user