diff --git a/middleware/compress.go b/middleware/compress.go index 3780ee5..fc0c31d 100644 --- a/middleware/compress.go +++ b/middleware/compress.go @@ -41,6 +41,8 @@ const ( DefaultCompressMinLength = 1024 ) +const IgnoreCompression = -128 + type ( // Compressor compressor interface Compressor interface { diff --git a/middleware/compress_test.go b/middleware/compress_test.go index 47f9fab..cc4f183 100644 --- a/middleware/compress_test.go +++ b/middleware/compress_test.go @@ -25,7 +25,6 @@ package middleware import ( "bytes" "errors" - "math" "math/rand" "net/http/httptest" "testing" @@ -102,7 +101,7 @@ func TestCompressMiddleware(t *testing.T) { }, DynamicLevel: func(c *elton.Context, bodySize int, encoding string) int { // 不指定压缩级别 - return math.MinInt + return IgnoreCompression }, }) diff --git a/middleware/gzip.go b/middleware/gzip.go index 342c70e..b1dbd18 100644 --- a/middleware/gzip.go +++ b/middleware/gzip.go @@ -26,7 +26,6 @@ import ( "bytes" "compress/gzip" "io" - "math" "github.com/vicanso/elton" ) @@ -56,7 +55,7 @@ func (g *GzipCompressor) Accept(c *elton.Context, bodySize int) (bool, string) { // Compress compress data by gzip func (g *GzipCompressor) Compress(buf []byte, levels ...int) (*bytes.Buffer, error) { level := g.getLevel() - if len(levels) != 0 && levels[0] != math.MinInt { + if len(levels) != 0 && levels[0] != IgnoreCompression { level = levels[0] } buffer := new(bytes.Buffer) diff --git a/middleware/gzip_test.go b/middleware/gzip_test.go index 8889868..5a1ee8b 100644 --- a/middleware/gzip_test.go +++ b/middleware/gzip_test.go @@ -26,7 +26,6 @@ import ( "bytes" "compress/gzip" "io/ioutil" - "math" "net/http/httptest" "testing" @@ -52,7 +51,7 @@ func TestGzipCompress(t *testing.T) { _, err := g.Compress([]byte(originalData), 1) assert.Nil(err) - buf, err := g.Compress([]byte(originalData), math.MinInt) + buf, err := g.Compress([]byte(originalData), IgnoreCompression) assert.Nil(err) r, err := gzip.NewReader(bytes.NewReader(buf.Bytes()))