Skip to content

Commit

Permalink
docs: update custom compress document
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Feb 26, 2022
1 parent 007cec1 commit eb6de7c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/custom_compress.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: 自定义压缩
- 根据响应头`Content-Type`判断只压缩文本类的响应数据
- 根据场景平衡压缩率与性能的选择,如内网的可以选择snappy,lz4等高效压缩算法

[elton-compress](https://github.com/vicanso/elton-compress)中间件提供了其它几种常用的压缩方式,包括`brotli`以及`snappy`等。如果要增加压缩方式,只需要实现`Compressor`的三个函数则可。
[elton-compress](https://github.com/vicanso/elton-compress)中间件提供了其它几种常用的压缩方式,包括`zstd`以及`snappy`等。如果要增加压缩方式,只需要实现`Compressor`的三个函数则可。

```go
// Compressor compressor interface
Expand Down Expand Up @@ -103,18 +103,19 @@ import (

"github.com/vicanso/elton"
compress "github.com/vicanso/elton-compress"
"github.com/vicanso/elton/middleware"
)

func main() {
d := elton.New()

conf := compress.Config{}
conf := middleware.CompressConfig{}
lz4 := &compress.Lz4Compressor{
Level: 2,
MinLength: 1024,
}
conf.AddCompressor(lz4)
d.Use(compress.New(conf))
d.Use(middleware.NewCompress(conf))

d.GET("/", func(c *elton.Context) (err error) {
b := new(bytes.Buffer)
Expand Down

0 comments on commit eb6de7c

Please sign in to comment.