Files
EdgeCommon/pkg/serverconfigs/http_compression_gzip_config.go

48 lines
1.3 KiB
Go
Raw Permalink Normal View History

2020-09-16 09:09:31 +08:00
package serverconfigs
import (
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
)
2021-09-29 19:37:32 +08:00
// HTTPGzipCompressionConfig gzip配置
type HTTPGzipCompressionConfig struct {
2020-09-29 17:23:11 +08:00
Id int64 `yaml:"id" json:"id"` // ID
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
Level int8 `yaml:"level" json:"level"` // 1-9
MinLength *shared.SizeCapacity `yaml:"minLength" json:"minLength"` // 最小压缩对象比如4m, 24k
MaxLength *shared.SizeCapacity `yaml:"maxLength" json:"maxLength"` // 最大压缩对象
Conds *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"` // 匹配条件
2020-09-16 09:09:31 +08:00
minLength int64
2020-09-29 17:23:11 +08:00
maxLength int64
2020-09-16 09:09:31 +08:00
}
2021-09-29 19:37:32 +08:00
// Init 校验
func (this *HTTPGzipCompressionConfig) Init() error {
2020-09-16 09:09:31 +08:00
if this.MinLength != nil {
this.minLength = this.MinLength.Bytes()
}
2020-09-29 17:23:11 +08:00
if this.MaxLength != nil {
this.maxLength = this.MaxLength.Bytes()
}
if this.Conds != nil {
err := this.Conds.Init()
if err != nil {
return err
}
}
2020-09-16 09:09:31 +08:00
return nil
}
2021-09-29 19:37:32 +08:00
// MinBytes 可压缩最小尺寸
func (this *HTTPGzipCompressionConfig) MinBytes() int64 {
2020-09-16 09:09:31 +08:00
return this.minLength
}
2021-09-29 19:37:32 +08:00
// MaxBytes 可压缩最大尺寸
func (this *HTTPGzipCompressionConfig) MaxBytes() int64 {
2020-09-29 17:23:11 +08:00
return this.maxLength
2020-09-16 09:09:31 +08:00
}