compress

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UseBrotli  = "br"
	UseGzip    = "gzip"
	UseDeflate = "deflate"
)

Variables

This section is empty.

Functions

func New

func New(option Option) gin.HandlerFunc

New a compress middleware, will use Option to config

Types

type DeflateOption added in v1.1.0

type DeflateOption struct {
	Level int
	Dict  []byte // leave empty for default
}

type Option added in v1.1.0

type Option struct {
	EnableMethods []string // enabled compress methods, will be matched in order
	GzipLevel     int
	BrotliOption  brotli.WriterOptions
	DeflateOption DeflateOption
}

Option can enable and config each compress method for simple needs please use UseAllBestSpeed or UseAllBestBestCompression

func UseAllBestBestCompression added in v1.1.0

func UseAllBestBestCompression() Option

func UseAllBestSpeed added in v1.1.0

func UseAllBestSpeed() Option

type ResponseWriter

type ResponseWriter struct {
	gin.ResponseWriter
	ComPressWriter io.WriteCloser
}

func NewBrotli

func NewBrotli(writer gin.ResponseWriter, option Option) *ResponseWriter

func NewDeflate

func NewDeflate(writer gin.ResponseWriter, option Option) *ResponseWriter

func NewGzip

func NewGzip(writer gin.ResponseWriter, option Option) *ResponseWriter

func (*ResponseWriter) Close

func (r *ResponseWriter) Close() error

func (*ResponseWriter) Write

func (r *ResponseWriter) Write(data []byte) (int, error)

func (*ResponseWriter) WriteHeader

func (r *ResponseWriter) WriteHeader(statusCode int)

func (*ResponseWriter) WriteString

func (r *ResponseWriter) WriteString(s string) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL