middleware/compress.go
func (c *Compressor) selectEncoder(h http.Header, w io.Writer) (io.Writer, string, func()) {
	header := h.Get("Accept-Encoding")

	// Parse the names of all accepted algorithms from the header.
	accepted := strings.Split(strings.ToLower(header), ",")

	// Find supported encoder by accepted list by precedence
	for _, name := range c.encodingPrecedence {
		if matchAcceptEncoding(accepted, name) {
			if pool, ok := c.pooledEncoders[name]; ok {
				encoder := pool.Get().(ioResetterWriter)
				cleanup := func() {
					pool.Put(encoder)
				}
				encoder.Reset(w)
				return encoder, name, cleanup

			}
			if fn, ok := c.encoders[name]; ok {
				return fn(w, c.level), name, func() {}
			}
		}

	}

	// No encoder found to match the accepted encoding
	return nil, "", func() {}
}
func (c *Compressor) selectEncoder(h http.Header, w io.Writer) (io.Writer, string, func()) {
	header := h.Get("Accept-Encoding")

	// Parse the names of all accepted algorithms from the header.
	accepted := strings.Split(strings.ToLower(header), ",")

	// Find supported encoder by accepted list by precedence
	for _, name := range c.encodingPrecedence {
		if matchAcceptEncoding(accepted, name) {
			if pool, ok := c.pooledEncoders[name]; ok {
				encoder := pool.Get().(ioResetterWriter)
				cleanup := func() {
					pool.Put(encoder)
				}
				encoder.Reset(w)
				return encoder, name, cleanup

			}
			if fn, ok := c.encoders[name]; ok {
				return fn(w, c.level), name, func() {}
			}
		}

	}

	// No encoder found to match the accepted encoding
	return nil, "", func() {}
}
func ( c * Compressor ) selectEncoder ( h http . Header , w io . Writer ) ( io . Writer , string , func ( ) ) { header := h . Get ( " " ) // Parse the names of all accepted algorithms from the header. accepted := strings . Split ( strings . ToLower ( header ) , " " ) // Find supported encoder by accepted list by precedence for _ , name := range c . encodingPrecedence { if matchAcceptEncoding ( accepted , name ) { if pool , ok := c . pooledEncoders [ name ] ; ok { encoder := pool . Get ( ) . ( ioResetterWriter ) cleanup := func ( ) { pool . Put ( encoder ) } encoder . Reset ( w ) return encoder , name , cleanup } if fn , ok := c . encoders [ name ] ; ok { return fn ( w , c . level ) , name , func ( ) { } } } } // No encoder found to match the accepted encoding return nil , " " , func ( ) { } }
// selectEncoder returns the encoder, the name of the encoder, and a closer function.
selectEncoder returns the encoder the name of the encoder and a closer function .