Compress
Fiber용 압축 미들웨어는 Accept-Encoding 헤더에 따라 gzip
, deflate
및 brotli
압축을 사용하여 응답을 압축합니다.
Signatures
func New(config ...Config) fiber.Handler
Examples
Fiber 웹 프레임워크의 일부인 미들웨어 패키지를 가져옵니다.
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/compress"
)
Fiber 앱을 초기화한 후 다음과 같은 가능성을 사용할 수 있습니다:
// 기본 구성 초기화
app.Use(compress.New())
// 또는 사용자 지정을 위해 구성 확장
app.Use(compress.New(compress.Config{
Level: compress.LevelBestSpeed, // 1
}))
// 특정 경로에 대해 미들웨어 건너뛰기
app.Use(compress.New(compress.Config{
Next: func(c *fiber.Ctx) bool {
return c.Path() == "/dont_compress"
},
Level: compress.LevelBestSpeed, // 1
}))
Config
Config
Property
Type
Description
Default
Next
func(*fiber.Ctx) bool
Next는 반환된 경우 이 미들웨어를 건너뛰는 함수를 정의합니다.
nil
Level
Level
Level은 압축 알고리즘을 결정합니다.
LevelDefault (0)
"Level" 필드에 가능한 값은 다음과 같습니다:
LevelDisabled (-1)
: 압축이 비활성화됩니다.LevelDefault (0)
: 기본 압축 수준입니다.LevelBestSpeed (1)
: 최상의 압축 속도입니다.LevelBestCompression (2)
: 최상의 압축입니다.
Default Config
var ConfigDefault = Config{
Next: nil,
Level: LevelDefault,
}
Constants
// 압축 수준
const (
LevelDisabled = -1
LevelDefault = 0
LevelBestSpeed = 1
LevelBestCompression = 2
)
Last updated