Config
Config controls Zincβs runtime behavior.
Default shapeβ
Important defaults include:
CaseSensitive: falseStrictRouting: falseAutoHead: trueAutoOptions: trueHandleMethodNotAllowed: trueBodyLimit: 4 << 20ReadTimeout: 5sWriteTimeout: 10sIdleTimeout: 120sProxyHeader: "X-Forwarded-For"RouteCacheSize: 1000
Main fieldsβ
| Field | Purpose |
|---|---|
ServerHeader | Override the server header |
CaseSensitive | Make route matching case-sensitive |
StrictRouting | Distinguish /users from /users/ |
AutoHead | Automatically support HEAD for GET routes |
AutoOptions | Automatically respond to OPTIONS |
HandleMethodNotAllowed | Return 405 when a path exists for another method |
BodyLimit | Maximum request body size |
ReadTimeout, WriteTimeout, IdleTimeout | Server timeouts |
ProxyHeader, TrustedProxies | Proxy-aware client IP behavior |
RequestBinder, Validator, Renderer, JSONCodec, ErrorHandler | Extension points |
RouteCacheSize | Router cache size |
Use NewWithConfig whenever your application needs more than Zincβs defaults.
Unset zero-value fields are normalized to safe defaults for body size, timeouts, proxy header, JSON codec, request binder, and error handler.
Proxy trustβ
ProxyHeader controls which forwarded header Zinc reads for c.IP() and c.IPs(). TrustedProxies controls when that header is trusted.
app := zinc.NewWithConfig(zinc.Config{
ProxyHeader: zinc.HeaderXForwardedFor,
TrustedProxies: []string{"10.0.0.1"},
})
Leave TrustedProxies empty when the app is exposed directly to users and forwarded headers should not be trusted.
Extension pointsβ
Use the extension fields to replace one part of Zinc without changing the handler API:
app := zinc.NewWithConfig(zinc.Config{
Validator: validator,
Renderer: renderer,
ErrorHandler: writeError,
})
RequestBinder controls request decoding, JSONCodec controls JSON encode/decode behavior, and ErrorHandler controls how returned errors are written.