mime

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package mime implements parts of the MIME spec similarly to the standard "mime" package. This package adds two functions, FileExtension and IsTextual. The other functions call through to the standard "mime" package functions of the same name.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtensionsByType

func ExtensionsByType(typ string) ([]string, error)

ExtensionsByType returns the extensions known to be associated with the MIME type typ. The returned extensions will each begin with a leading dot, as in ".html". When typ has no associated extensions, ExtensionsByType returns a nil slice.

func FileExtension

func FileExtension(mimeType string) string

FileExtension returns the extensions known to be associated with the MIME type mimeType. This is similar to ExtensionsByType, except that these are treated as special cases:

* "text/plain": ".txt" * "text/html": ".html" * "application/octet-stream": ".bin" * "application/xml": ".xml"

func FormatMediaType

func FormatMediaType(t string, param map[string]string) string

FormatMediaType serializes mediatype t and the parameters param as a media type conforming to RFC 2045 and RFC 2616. The type and parameter names are written in lower-case. When any of the arguments result in a standard violation then FormatMediaType returns the empty string.

func IsTextual

func IsTextual(contentType string) bool

IsTextual tests a media type to determine whether it describes text or binary content. Textual types are

* "text/*" * "application/json" * "application/xml" * "application/*+json" * "application/*+xml" * "image/*+xml"

where "*" is a wildcard. Deprecated: use github.com/rickb777/acceptable [header.ResponseType].

func ParseMediaType

func ParseMediaType(v string) (mediatype string, params map[string]string, err error)

ParseMediaType parses a media type value and any optional parameters, per RFC 1521. Media types are the values in Content-Type and Content-Disposition headers (RFC 2183). On success, ParseMediaType returns the media type converted to lowercase and trimmed of white space and a non-nil map. If there is an error parsing the optional parameter, the media type will be returned along with the error ErrInvalidMediaParameter. The returned map, params, maps from the lowercase attribute to the attribute value with its case preserved.

func TypeByExtension

func TypeByExtension(ext string) string

TypeByExtension returns the MIME type associated with the file extension ext. The extension ext should begin with a leading dot, as in ".html". When ext has no associated type, TypeByExtension returns "".

Extensions are looked up first case-sensitively, then case-insensitively.

The built-in table is small but on unix it is augmented by the local system's MIME-info database or mime.types file(s) if available under one or more of these names:

/usr/local/share/mime/globs2
/usr/share/mime/globs2
/etc/mime.types
/etc/apache2/mime.types
/etc/apache/mime.types

On Windows, MIME types are extracted from the registry.

Text types have the charset parameter set to "utf-8" by default.

Types

This section is empty.

Jump to

Keyboard shortcuts

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