Package for retrieving the mime type given an extension.
Features and limitations
Must be given a filename that contains a list of mimetypes followed by extensions. Typically /etc/mime.types.
Will only read the file once, then store the lookup table in memory. This results in fast lookups.
Has a lookup table for the most common mime types, if no mime information is found.
Example
package main
import (
"fmt"
"github.com/xyproto/mime"
)
func main() {
// Read inn the list of mime types and extensions.
// Set everything to UTF-8 when writing headers
m := mime.New("/etc/mime.types", true)
// Print the mime type for svg.
fmt.Println(m.Get("svg"))
}
New creates a new Reader. The filename is a list of mimetypes and extensions.
If utf8 is true, "; charset=utf-8" will be added when setting http headers.