This method creates a new App named instance. You can pass optional settings when creating a new instance.
Signaturefunc New(config ...Config) *App
Example// Default configapp := fiber.New()// ...
You can pass an optional Config when creating a new Fiber instance.
Example// Custom configapp := fiber.New(fiber.Config{Prefork: true,CaseSensitive: true,StrictRouting: true,ServerHeader: "Fiber",})// ...
Config fields
Property | Type | Description | Default |
Prefork |
| Enables use of the |
|
ServerHeader |
| Enables the |
|
StrictRouting |
| When enabled, the router treats |
|
CaseSensitive |
| When enabled, |
|
Immutable |
| When enabled, all values returned by context methods are immutable. By default, they are valid until you return from the handler; see issue #185. |
|
UnescapePath |
| Converts all encoded characters in the route back before setting the path for the context, so that the routing can also work with URL encoded special characters |
|
ETag |
| 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. |
|
BodyLimit |
| Sets the maximum allowed size for a request body, if the size exceeds the configured limit, it sends |
|
Concurrency |
| Maximum number of concurrent connections. |
|
Views |
| Views is the interface that wraps the Render function. See our Template Middleware for supported engines. |
|
ReadTimeout |
| The amount of time allowed to read the full request, including the body. The default timeout is unlimited. |
|
WriteTimeout |
| The maximum duration before timing out writes of the response. The default timeout is unlimited. |
|
IdleTimeout |
| 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. |
|
ReadBufferSize |
| per-connection buffer size for requests' reading. This also limits the maximum header size. Increase this buffer if your clients send multi-KB RequestURIs and/or multi-KB headers (for example, BIG cookies). |
|
WriteBufferSize |
| Per-connection buffer size for responses' writing. |
|
CompressedFileSuffix |
| Adds a suffix to the original file name and tries saving the resulting compressed file under the new file name. |
|
ProxyHeader |
| This will enable |
|
GETOnly |
| Rejects all non-GET requests if set to true. This option is useful as anti-DoS protection for servers accepting only GET requests. The request size is limited by ReadBufferSize if GETOnly is set. |
|
ErrorHandler |
| ErrorHandler is executed when an error is returned from fiber.Handler. |
|
DisableKeepalive |
| Disable keep-alive connections, the server will close incoming connections after sending the first response to the client |
|
DisableDefaultDate |
| When set to true causes the default date header to be excluded from the response. |
|
DisableDefaultContentType |
| When set to true, causes the default Content-Type header to be excluded from the Response. |
|
DisableHeaderNormalizing |
| By default all header names are normalized: conteNT-tYPE -> Content-Type |
|
DisableStartupMessage |
| When set to true, it will not print out debug information |
|
NewError creates a new HTTPError instance with an optional message.
Signaturefunc NewError(code int, message ...string) *Error
Exampleapp.Get("/", func(c *fiber.Ctx) error {return fiber.NewError(782, "Custom error message")})
IsChild determines if the current process is a result of Prefork.
Signaturefunc IsChild() bool
Example// Prefork will spawn child processesapp := fiber.New(fiber.Config{Prefork: true,})if !fiber.IsChild() {fmt.Println("I'm the parent process")} else {fmt.Println("I'm a child process")}// ...