Settings
You can pass application settings when calling New
.
- func main() {
- // Pass Settings creating a new instance
- app := fiber.New(&fiber.Settings{
- Prefork: true,
- CaseSensitive: true,
- StrictRouting: true,
- ServerHeader: "Fiber",
- })
- // ...
- app.Listen(3000)
- }
Or change the settings after initializing an app
.
- func main() {
- app := fiber.New()
- // Or change Settings after creating an instance
- app.Settings.Prefork = true
- app.Settings.CaseSensitive = true
- app.Settings.StrictRouting = true
- app.Settings.ServerHeader = "Fiber"
- // ...
- app.Listen(3000)
- }
Settings fields
Property | Type | Description | Default |
---|---|---|---|
Prefork | bool | Enables use of theSOREUSEPORT socket option. This will spawn multiple Go processes listening on the same port. learn more about socket sharding. | false |
ServerHeader | string | Enables the Server HTTP header with the given value. | “” |
StrictRouting | bool | When enabled, the router treats /foo and /foo/ as different. Otherwise, the router treats /foo and /foo/ as the same. | false |
CaseSensitive | bool | When enabled, /Foo and /foo are different routes. When disabled, /Foo and /foo are treated the same. | false |
Immutable | bool | When enabled, all values returned by context methods are immutable. By default they are valid until you return from the handler, see issue #185. | false |
BodyLimit | int | Sets the maximum allowed size for a request body, if the size exceeds the configured limit, it sends 413 - Request Entity Too Large response. | 4 1024 1024 |
Concurrency | int | Maximum number of concurrent connections. | 256 * 1024 |
DisableKeepalive | bool | Disable keep-alive connections, the server will close incoming connections after sending the first response to client | false |
DisableDefaultDate | bool | When set to true causes the default date header to be excluded from the response. | false |
DisableDefaultContentType | bool | When set to true, causes the default Content-Type header to be excluded from the Response. | false |
DisableStartupMessage | bool | When set to true, it will not print out the fiber ASCII and “listening” on message | false |
ETag | bool | Enable or disable ETag header generation, since both weak and strong etags are generated using the same hashing method (CRC-32). Weak ETags are the default when enabled. | false |
TemplateEngine | func(raw string, bind interface{}) (string, error) | You can specify a custom template function to render different template languages. See our Template Middleware **_for presets. | nil |
TemplateFolder | string | A directory for the application’s views. If a directory is set, this will be the prefix for all template paths. c.Render(“home”, data) -> ./views/home.pug | “” |
TemplateExtension | string | If you preset the template file extension, you do not need to provide the full filename in the Render function: c.Render(“home”, data) -> home.pug | “html” |
ReadTimeout | time.Duration | The amount of time allowed to read the full request including body. Default timeout is unlimited. | nil |
WriteTimeout | time.Duration | The maximum duration before timing out writes of the response. Default timeout is unlimited. | nil |
IdleTimeout | time.Duration | The maximum amount of time to wait for the next request when keep-alive is enabled. If IdleTimeout is zero, the value of ReadTimeout is used. | nil |