wood chen 723b73d748 feat: add compression support and update deployment workflow
add brotli and gzip compression support, update docker-compose and deployment script
2024-10-30 07:43:17 +08:00

24 lines
451 B
Go

package compression
import (
"io"
"github.com/andybalholm/brotli"
)
type BrotliCompressor struct {
level int
}
func NewBrotliCompressor(level int) *BrotliCompressor {
// 确保level在有效范围内 (0-11)
if level < 0 || level > 11 {
level = brotli.DefaultCompression
}
return &BrotliCompressor{level: level}
}
func (b *BrotliCompressor) Compress(w io.Writer) (io.WriteCloser, error) {
return brotli.NewWriterLevel(w, b.level), nil
}