runtime

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package runtime 提供应用程序运行时的依赖注入容器 该包使用 uber 的 dig 库来管理依赖项注入

Index

Constants

View Source
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.

View Source
const DefaultShutdownTimeout = 30 * time.Second

DefaultShutdownTimeout is used when server.shutdown_timeout is unset.

Variables

This section is empty.

Functions

func GetContainer

func GetContainer() *dig.Container

GetContainer 返回全局依赖注入容器的引用 供其他包使用以注册或获取服务

func LogGinRouteCount

func LogGinRouteCount(ctx context.Context)

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

func LogStartupEnv(ctx context.Context)

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

func ServerStartedAt() time.Time

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

func ServerUptime() time.Duration

ServerUptime returns elapsed time since MarkServerStarted. Zero when unset.

func ShutdownBudgets

func ShutdownBudgets(total time.Duration) (drain, cleanup time.Duration)

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.

func WaitFor

func WaitFor(ch <-chan struct{}, timeout time.Duration) bool

WaitFor reports whether ch was received before timeout. timeout <= 0 waits until ch is received. The boolean is false only when the timeout wins.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL