Documentation
¶
Overview ¶
Package runtime 提供应用程序运行时的依赖注入容器 该包使用 uber 的 dig 库来管理依赖项注入
Index ¶
- Constants
- func GetContainer() *dig.Container
- func LogGinRouteCount(ctx context.Context)
- func LogStartupEnv(ctx context.Context)
- func MarkServerStarted()
- func ServerStartedAt() time.Time
- func ServerUptime() time.Duration
- func ShutdownBudgets(total time.Duration) (drain, cleanup time.Duration)
- func SilenceGinRouteSpam()
- func WaitFor(ch <-chan struct{}, timeout time.Duration) bool
Constants ¶
const CleanupBudget = 5 * time.Second
CleanupBudget is reserved from the configured shutdown timeout so connection drain cannot consume the whole grace period before process cleanup runs. Supervisors often use the same number for termination grace (Kubernetes defaults to 30s), so drain and cleanup share one budget instead of stacking.
const DefaultShutdownTimeout = 30 * time.Second
DefaultShutdownTimeout is used when server.shutdown_timeout is unset.
Variables ¶
This section is empty.
Functions ¶
func LogGinRouteCount ¶
LogGinRouteCount writes a single summary line for the number of routes Gin registered. Safe to call even if SilenceGinRouteSpam wasn't called (it just becomes a no-op).
func LogStartupEnv ¶
LogStartupEnv prints a single banner block summarising the curated set of env vars in startupEnvVars. Sensitive values are reported as "set (N chars)" — the goal is to give the operator confidence the config they expected actually landed, without echoing secrets to logs.
Output format (one line per var to stay grep-able):
[startup-env] SYSTEM_AES_KEY=set (32 chars) [startup-env] JWT_SECRET=<unset> [startup-env] DB_DRIVER=postgres
Special call-outs are printed afterwards for misconfigurations that would silently degrade behaviour (e.g. SYSTEM_AES_KEY set but wrong length is treated as unset by crypto.GetAESKey — easy to miss without a loud warning).
func MarkServerStarted ¶
func MarkServerStarted()
MarkServerStarted records the instant the WeKnora server process started. Call once from main() before heavy init so uptime reflects the full process lifetime, not merely when the HTTP listener binds.
func ServerStartedAt ¶
ServerStartedAt returns the boot instant in UTC. Zero when MarkServerStarted was not called (e.g. some tests); callers should treat zero as unknown.
func ServerUptime ¶
ServerUptime returns elapsed time since MarkServerStarted. Zero when unset.
func ShutdownBudgets ¶
ShutdownBudgets splits total into an HTTP drain budget and a cleanup budget. Their sum equals total. total <= 0 uses DefaultShutdownTimeout. When total is too small to reserve CleanupBudget, the two halves are equal.
func SilenceGinRouteSpam ¶
func SilenceGinRouteSpam()
SilenceGinRouteSpam mutes Gin's per-route "[GIN-debug] METHOD path --> handler" lines that flood the startup log with one entry per registered route (we have ~150 of them). DebugMode features (panic recovery stacktraces, runtime warnings) are preserved.
In place of the per-route spam, prints a single summary line at the end of router build with the route count.
Call once at the start of main(), before container.BuildContainer.
Types ¶
This section is empty.