让 Fiber 更快

原文: https://docs.gofiber.io/guide/faster-fiber

⚡ Make Fiber Faster 让 Fiber 更快

Custom JSON Encoder/Decoder 自定义 JSON 编码器/解码器

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:

​ 自 Fiber v2.32.0 起,我们使用 encoding/json 作为默认 json 库,因为它稳定且可生产。但是,与第三方库相比,标准库有点慢。如果您对 encoding/json 的性能不满意,我们建议您使用以下库:

Example 示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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,
    })

    # ...
}

References 参考

最后修改 October 10, 2024: 更新 (a4b8f85)