compress

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package compress 提供一个支持内容压缩的中间件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBrotli

func NewBrotli(w io.Writer) (io.WriteCloser, error)

NewBrotli 新建 br 算法

func NewDeflate

func NewDeflate(w io.Writer) (io.WriteCloser, error)

NewDeflate 新建 deflate 算法

func NewGzip

func NewGzip(w io.Writer) (io.WriteCloser, error)

NewGzip 新建 gzip 算法

Types

type Compress

type Compress struct {
	// contains filtered or unexported fields
}

Compress 提供压缩功能的中件间

func New

func New(errlog *log.Logger, writers map[string]WriterFunc, types ...string) *Compress

New 构建一个支持压缩的中间件

types 表示需要进行压缩处理的 mimetype 类型,可以是以下格式:

  • application/json 具体类型;
  • text* 表示以 text 开头的所有类型;
  • * 表示所有类型,一旦指定此值,则其它设置都将被忽略;

func (*Compress) AddType added in v2.4.0

func (c *Compress) AddType(types ...string)

AddType 添加对媒体类型的支持

types 表示需要进行压缩处理的 mimetype 类型,可以是以下格式:

  • application/json 具体类型;
  • text* 表示以 text 开头的所有类型;
  • * 表示所有类型,一旦指定此值,则其它设置都将被忽略;

func (*Compress) DeleteType added in v2.4.0

func (c *Compress) DeleteType(types ...string)

DeleteType 删除对媒体类型的支持

types 的格式可参考 AddType 方法。

func (*Compress) Middleware

func (c *Compress) Middleware(next http.Handler) http.Handler

Middleware 将当前中间件应用于 next

func (*Compress) MiddlewareFunc

func (c *Compress) MiddlewareFunc(next func(w http.ResponseWriter, r *http.Request)) http.Handler

MiddlewareFunc 将当前中间件应用于 next

func (*Compress) SetWriter added in v2.4.0

func (c *Compress) SetWriter(name string, w WriterFunc)

SetWriter 设置压缩算法

如果 w 为 nil,则表示去掉此算法的支持。

type WriterFunc

type WriterFunc func(w io.Writer) (io.WriteCloser, error)

WriterFunc 定义了将一个 io.Writer 声明为具有压缩功能的 io.WriteCloser

Jump to

Keyboard shortcuts

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