compressible

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2017 License: MIT Imports: 3 Imported by: 4

README

compressible-go

Build Status Coverage Status License GoDoc

Compressible Content-Type / mime checking for Go.

Demo

import (
  "github.com/teambition/compressible-go"
)

fmt.Println(compressible.Is("text/html"))
// -> true

fmt.Println(compressible.Is("image/png"))
// -> false

var wt compressible.WithTrashold = 1024

fmt.Println(wt.Compressible("text/html", 1023))
// -> false

Work with gear:

package main

import (
  "github.com/teambition/compressible-go"
  "github.com/teambition/gear"
  "github.com/teambition/gear/middleware/static"
)

func main() {
  app := gear.New()
  app.Set(gear.SetCompress, compressible.WithThreshold(1024))

  // Add a static middleware
  app.Use(static.New(static.Options{
    Root:   "./",
    Prefix: "/",
  }))
  app.Error(app.Listen(":3000")) // http://127.0.0.1:3000/
}

Documentation

The docs can be found at godoc.org, as usual.

License

MIT

Documentation

Overview

Package compressible provides Compressible Content-Type / mime checking for Go.

Example
fmt.Println(compressible.Is("text/html"))
// -> true

fmt.Println(compressible.Is("image/png"))
// -> false

var wt compressible.WithThreshold = 1024

fmt.Println(wt.Compressible("text/html", 1023))
// -> false
Output:

Index

Examples

Constants

View Source
const Version = "1.0.1"

Version is Gear's version

Variables

This section is empty.

Functions

func Is

func Is(contentType string) bool

Is checks the response Content-Type to determine whether to compress. Using mime database https://github.com/GitbookIO/mimedb to find which Content-Type is compressible. All types that not in mimedb but have the scheme of "text/*", "*/*+json", "*/*+text", "*/*+xml" are considered as compressible.

func Load

func Load() error

Load loads all extensions and their content types of https://github.com/GitbookIO/mimedb to offical "mime" package. Recommond to apply this function in your main package's init function.

Types

type WithThreshold

type WithThreshold int

WithThreshold is an impelementation with transhold. The transhold defines the // minimun content length to enable compressible check.

func (WithThreshold) Compressible

func (wt WithThreshold) Compressible(contentType string, contentLength int) bool

Compressible checks the response Content-Type to determine whether to compress. Using mime database https://github.com/GitbookIO/mimedb to find which Content-Type is compressible and WithThreshold as content length transhold All types that not in mimedb but have the scheme of "text/*", "*/*+json", "*/*+text", "*/*+xml" are considered as compressible.

Jump to

Keyboard shortcuts

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