Compress

lunny edited this page Dec 29, 2014 · 2 revisions
  • Compress

Tango has a default compress handler to compress indicated static files according extensions like .js,.css,.html. Also, you can use some tango ticks to ask action to compress. For example:

type CompressExample struct {
	tango.Compress // add this for ask compress according request accept-encoding, if no accept-encoding, not compress
}

func (CompressExample) Get() string {
	return fmt.Sprintf("This is a auto compress text")
}

o := tango.Classic()
o.Get("/", new(CompressExample))
o.Run()
type GZipExample struct {
	tango.GZip // add this for ask compress to GZip, if accept-encoding has no gzip, then not compress
}

func (GZipExample) Get() string {
	return fmt.Sprintf("This is a gzip compress text")
}

o := tango.Classic()
o.Get("/", new(GZipExample))
o.Run()
type DeflateExample struct {
	tango.Deflate // add this for ask compress to Deflate, if not support then not compress
}

func (DeflateExample) Get() string {
	return fmt.Sprintf("This is a deflate compress text")
}

o := tango.Classic()
o.Get("/", new(DeflateExample))
o.Run()
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.