Skip to content

Commit

Permalink
Merge pull request #252 from efectn/master
Browse files Browse the repository at this point in the history
Add new guide about speed, add missing config fields
  • Loading branch information
ReneWerner87 committed Apr 15, 2022
2 parents c789ea2 + e7a1860 commit c81363b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions SUMMARY.md
Expand Up @@ -39,6 +39,7 @@
* [🐛 Error Handling](guide/error-handling.md)
* [🔎 Validation](guide/validation.md)
* [🪝 Hooks](guide/hooks.md)
* [⚡ Make Fiber Faster](guide/faster-fiber.md)


## Extra
Expand Down
4 changes: 4 additions & 0 deletions api/fiber.md
Expand Up @@ -78,6 +78,10 @@ app := fiber.New(fiber.Config{
| DisablePreParseMultipartForm | `bool` | Will not pre parse Multipart Form data if set to true. This option is useful for servers that desire to treat multipart form data as a binary blob, or choose when to parse the data. | `false` |
| StreamRequestBody | `bool` | StreamRequestBody enables request body streaming, and calls the handler sooner when given body is larger then the current limit. | `false` |
| EnablePrintRoutes | `bool` | EnablePrintRoutes enables print all routes with their method, path, name and handler.. | `false` |
| Network | `string` | Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only)<br><br>**WARNING:** When prefork is set to true, only "tcp4" and "tcp6" can be chosen. | `NetworkTCP4` |
| JSONEncoder | `utils.JSONMarshal` | Allowing for flexibility in using another json library for encoding. | `json.Marshal` |
| JSONDecoder | `utils.JSONUnmarshal` | Allowing for flexibility in using another json library for decoding. | `json.Unmarshal` |


## NewError

Expand Down
34 changes: 34 additions & 0 deletions guide/faster-fiber.md
@@ -0,0 +1,34 @@
# ⚡ Make Fiber Faster

## Custom JSON Encoder/Decoder
Since Fiber v2.32.0, we use **encoding/json** as default json library due to stability and producibility. However, the standard library is a bit slow compared to 3rd party libraries. If you're not happy with the performance of **encoding/json**, we recommend you to use these libraries:
- [goccy/go-json](https://github.com/goccy/go-json1)
- [bytedance/sonic](https://github.com/bytedance/sonic)
- [segmentio/encoding](https://github.com/segmentio/encoding)
- [mailru/easyjson](https://github.com/mailru/easyjson)
- [minio/simdjson-go](https://github.com/minio/simdjson-go)
- [wI2L/jettison](https://github.com/wI2L/jettison)

{% code title="Example" %}
```go
package main

import "github.com/gofiber/fiber/v2"
import "github.com/goccy/go-json"

func main() {
app := fiber.New(fiber.Config{
JSONEncoder: json.Marshal,
JSONDecoder: json.Unmarshal,
})

# ...
}
```
{% endcode %}

### References
- [Set custom JSON encoder for client](../api/client.md#jsonencoder)
- [Set custom JSON decoder for client](../api/client.md#jsondecoder)
- [Set custom JSON encoder for application](../api/fiber.md#config)
- [Set custom JSON decoder for application](../api/fiber.md#config)

0 comments on commit c81363b

Please sign in to comment.