# README
GZIP zoox's middleware
Zoox middleware to enable GZIP
support.
Usage
Download and install it:
go get github.com/go-zoox/gzip
Import it in your code:
import "github.com/go-zoox/gzip"
Canonical example:
package main
import (
"fmt"
"net/http"
"time"
"github.com/go-zoox/gzip"
"github.com/go-zoox/zoox"
)
func main() {
r := zoox.New()
r.Use(gzip.Gzip(gzip.DefaultCompression))
r.Get("/ping", func(c *zoox.Context) {
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
})
// Listen and Server in 0.0.0.0:8080
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}
Customized Excluded Extensions
package main
import (
"fmt"
"net/http"
"time"
"github.com/go-zoox/gzip"
"github.com/go-zoox/zoox"
)
func main() {
r := zoox.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedExtensions([]string{".pdf", ".mp4"})))
r.Get("/ping", func(c *zoox.Context) {
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
})
// Listen and Server in 0.0.0.0:8080
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}
Customized Excluded Paths
package main
import (
"fmt"
"net/http"
"time"
"github.com/go-zoox/gzip"
"github.com/go-zoox/zoox"
)
func main() {
r := zoox.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPaths([]string{"/api/"})))
r.Get("/ping", func(c *zoox.Context) {
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
})
// Listen and Server in 0.0.0.0:8080
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}
Customized Excluded Paths
package main
import (
"fmt"
"net/http"
"time"
"github.com/go-zoox/gzip"
"github.com/go-zoox/zoox"
)
func main() {
r := zoox.Default()
r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPathsRegexs([]string{".*"})))
r.Get("/ping", func(c *zoox.Context) {
c.String(http.StatusOK, "pong "+fmt.Sprint(time.Now().Unix()))
})
// Listen and Server in 0.0.0.0:8080
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}
Thanks
- This project is modified from gin-gzip.
License
GoZoox is released under the MIT License.
# Packages
No description provided by the author
# Functions
DefaultDecompressHandle is the default decompress handle.
Gzip is a gzip middleware for zoox.
NewExcludedExtensions creates a new ExcludedExtensions map.
NewExcludedPathesRegexs creates a new ExcludedPathesRegexs.
NewExcludedPaths creates a new ExcludedPaths.
WithDecompressFn is an option for setting a custom decompress function.
WithExcludedExtensions is an option for excluding compression for certain file extensions.
WithExcludedPaths is an option for excluding compression for certain paths.
WithExcludedPathsRegexs is an option for excluding compression for certain paths.
# Constants
BestCompression is the level of best compression.
BestSpeed is the level of best speed.
DefaultCompression is the default compression level.
NoCompression is the level of no compression.
# Variables
DefaultExcludedExtentions is the default excluded extensions.
DefaultOptions is the default options for gzip middleware.
Version is the current version of the package.
# Type aliases
ExcludedExtensions is extensions map, using map for better lookup performance.
ExcludedPathesRegexs ...
ExcludedPaths ...
Option is the type of function that can be passed to WithExcludedExtensions, WithExcludedPaths, WithExcludedPathsRegexs, WithDecompressFn.