Adding upstream version 2.52.6.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
a960158181
commit
6d002e9543
441 changed files with 95392 additions and 0 deletions
56
middleware/compress/config.go
Normal file
56
middleware/compress/config.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package compress
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// Config defines the config for middleware.
|
||||
type Config struct {
|
||||
// Next defines a function to skip this middleware when returned true.
|
||||
//
|
||||
// Optional. Default: nil
|
||||
Next func(c *fiber.Ctx) bool
|
||||
|
||||
// Level determines the compression algorithm
|
||||
//
|
||||
// Optional. Default: LevelDefault
|
||||
// LevelDisabled: -1
|
||||
// LevelDefault: 0
|
||||
// LevelBestSpeed: 1
|
||||
// LevelBestCompression: 2
|
||||
Level Level
|
||||
}
|
||||
|
||||
// Level is numeric representation of compression level
|
||||
type Level int
|
||||
|
||||
// Represents compression level that will be used in the middleware
|
||||
const (
|
||||
LevelDisabled Level = -1
|
||||
LevelDefault Level = 0
|
||||
LevelBestSpeed Level = 1
|
||||
LevelBestCompression Level = 2
|
||||
)
|
||||
|
||||
// ConfigDefault is the default config
|
||||
var ConfigDefault = Config{
|
||||
Next: nil,
|
||||
Level: LevelDefault,
|
||||
}
|
||||
|
||||
// Helper function to set default values
|
||||
func configDefault(config ...Config) Config {
|
||||
// Return default config if nothing provided
|
||||
if len(config) < 1 {
|
||||
return ConfigDefault
|
||||
}
|
||||
|
||||
// Override default config
|
||||
cfg := config[0]
|
||||
|
||||
// Set default values
|
||||
if cfg.Level < LevelDisabled || cfg.Level > LevelBestCompression {
|
||||
cfg.Level = ConfigDefault.Level
|
||||
}
|
||||
return cfg
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue