Skip to content

Commit

Permalink
Add gear.ThresholdCompress instead of `github.com/teambition/compre…
Browse files Browse the repository at this point in the history
…ssible-go`.
  • Loading branch information
zensh committed Aug 8, 2023
1 parent 17cc7bb commit e044e81
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file starting fro
This project adheres to [Semantic Versioning](http://semver.org/).

-----
## [1.27.3] - 2023-08-08

**Changed:**

- Add `gear.ThresholdCompress` instead of `github.com/teambition/compressible-go`.
- Update dependencies.

## [1.27.2] - 2023-07-10

**Changed:**

- Add gearproxy as example.

## [1.27.1] - 2023-07-04

**Changed:**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func main() {
app.Use(cors.New())
app.Use(static.New(static.Options{Root: *path}))

logging.Println("staticgo v1.1.0, created by https://github.com/teambition/gear")
logging.Println("staticgo v1.2.0, created by https://github.com/teambition/gear")
logging.Printf("listen: %s, serve: %s\n", *address, *path)

if *certFile != "" && *keyFile != "" {
Expand Down
21 changes: 15 additions & 6 deletions compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,32 @@ type Compressible interface {
type DefaultCompress struct{}

// Compressible implemented Compress interface.
// Recommend https://github.com/teambition/compressible-go.
//
// import "github.com/teambition/compressible-go"
func (d *DefaultCompress) Compressible(contentType string, contentLength int) bool {
if contentLength > 0 && contentLength <= 1024 {
return false
}
return contentType != ""
}

// ThresholdCompress is an impelementation with transhold. The transhold defines the // minimun content length to enable compressible check.
type ThresholdCompress int

// Compressible implemented Compress interface.
//
// app := gear.New()
// app.Set(gear.SetCompress, compressible.WithThreshold(1024))
// app.Set(gear.SetCompress, gear.ThresholdCompress(128))
//
// // Add a static middleware
// app.Use(static.New(static.Options{
// Root: "./",
// Prefix: "/",
// }))
// app.Error(app.Listen(":3000")) // http://127.0.0.1:3000/
func (d *DefaultCompress) Compressible(contentType string, contentLength int) bool {
if contentLength > 0 && contentLength <= 1024 {
func (tc ThresholdCompress) Compressible(contentType string, contentLength int) bool {
if contentLength < int(tc) {
return false
}

return contentType != ""
}

Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ Learn more at https://github.com/teambition/gear
package gear

// Version is Gear's version
const Version = "1.27.1"
const Version = "1.27.3"
5 changes: 2 additions & 3 deletions example/staticgo/staticgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"flag"

"github.com/teambition/compressible-go"
"github.com/teambition/gear"
"github.com/teambition/gear/logging"
"github.com/teambition/gear/middleware/cors"
Expand All @@ -20,13 +19,13 @@ var (
func main() {
flag.Parse()
app := gear.New()
app.Set(gear.SetCompress, compressible.WithThreshold(1024))
app.Set(gear.SetCompress, gear.ThresholdCompress(128))

app.UseHandler(logging.Default(true))
app.Use(cors.New())
app.Use(static.New(static.Options{Root: *path}))

logging.Println("staticgo v1.1.0, created by https://github.com/teambition/gear")
logging.Println("staticgo v1.2.0, created by https://github.com/teambition/gear")
logging.Printf("listen: %s, serve: %s\n", *address, *path)

if *certFile != "" && *keyFile != "" {
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ require (
github.com/go-http-utils/cookie v1.3.1
github.com/go-http-utils/negotiator v1.0.0
github.com/stretchr/testify v1.8.4
github.com/teambition/compressible-go v1.0.1
github.com/teambition/trie-mux v1.5.2
golang.org/x/net v0.11.0
golang.org/x/net v0.14.0
)

require (
github.com/GitbookIO/mimedb v0.0.0-20180329142916-39fdfdb4def4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/text v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
22 changes: 4 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
github.com/GitbookIO/mimedb v0.0.0-20180329142916-39fdfdb4def4 h1:WM2ftu7PazeqAxMiT0j0XmYiWW1xX99v5/PbW2UKAzE=
github.com/GitbookIO/mimedb v0.0.0-20180329142916-39fdfdb4def4/go.mod h1:0JA2lIXs/dl3RUgHP5ivwjl3f0g+X2BQz3zWnq8IJa4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -12,27 +10,15 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/teambition/compressible-go v1.0.1 h1:9lLUAWKkLcuLGVLjVW0VzXacjH89px93PbkwmIw0lGU=
github.com/teambition/compressible-go v1.0.1/go.mod h1:K91wjCUqzpuY2ZpSi039mt4WzzjMGxPFMZHHTEoTvak=
github.com/teambition/trie-mux v1.5.2 h1:ALTagFwKZXkn1vfSRlODlmoZg+NMeWAm4dyBPQI6a8w=
github.com/teambition/trie-mux v1.5.2/go.mod h1:0Woh4KOHSN9bkJ66eWmLs8ltrEKw+fnZbFaHFfbMrtc=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
Expand Down

0 comments on commit e044e81

Please sign in to comment.