Skip to content

Configuration ​

Added: v1.0.0

Router Config ​

Pass a zen.Config to zen.New to customize server behavior:

go
config := zen.DefaultConfig()
config.ReadTimeout = 10 * time.Second
config.WriteTimeout = 20 * time.Second
config.ShutdownTimeout = 10 * time.Second
r := zen.New(":8080", config)

Config Options ​

OptionDefaultDescription
ReadTimeout0Max duration for reading the entire request body (0 = stdlib default)
WriteTimeout0Max duration for writing the response (0 = stdlib default)
IdleTimeout0Max idle time for keep-alive connections (0 = stdlib default)
ReadHeaderTimeout0Max duration for reading request headers (0 = stdlib default)
MaxHeaderBytes0Maximum size of request headers (0 = stdlib default, no limit)
ShutdownTimeout5sGraceful shutdown timeout (Run blocks until done or timeout)

Internal Logging ​

Zen's internal diagnostics (recovered panics, debug traces) are written by an unexported internal logger prefixed with [ZEN] to os.Stderr - there is no public logging API to configure. Request access logs from the Logger middleware go to os.Stdout. To route both through your own structured logger, wrap the middleware or capture the streams.

Environment Variables ​

Type-safe environment parsing with defaults and required-value variants:

go
dbURL := env.GetString("DATABASE_URL", "postgres://localhost:5432")
port := env.GetInt("PORT", 8080)
debug := env.GetBool("DEBUG", false)
timeout := env.GetDuration("TIMEOUT", 30*time.Second)

// Panics if unset
dbURL := env.MustGetString("DATABASE_URL")

Released under the MIT License.