Skip to content

Commit

Permalink
fix: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Oct 17, 2021
1 parent 35b5cd5 commit 85b23f0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 2 additions & 0 deletions middleware/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (
DefaultCompressMinLength = 1024
)

const IgnoreCompression = -128

type (
// Compressor compressor interface
Compressor interface {
Expand Down
3 changes: 1 addition & 2 deletions middleware/compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ package middleware
import (
"bytes"
"errors"
"math"
"math/rand"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestCompressMiddleware(t *testing.T) {
},
DynamicLevel: func(c *elton.Context, bodySize int, encoding string) int {
// 不指定压缩级别
return math.MinInt
return IgnoreCompression
},
})

Expand Down
3 changes: 1 addition & 2 deletions middleware/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"bytes"
"compress/gzip"
"io"
"math"

"github.com/vicanso/elton"
)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions middleware/gzip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"bytes"
"compress/gzip"
"io/ioutil"
"math"
"net/http/httptest"
"testing"

Expand All @@ -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()))
Expand Down

0 comments on commit 85b23f0

Please sign in to comment.