Documentation
¶
Overview ¶
Package mimetypes is a pure-Go (CGO-free) reimplementation of Ruby's MIME::Types registry — the data model and lookup behaviour of the mime-types gem (backed by the mime-types-data registry), faithful to MRI.
The complete IANA/registry dataset shipped by the mime-types-data gem is embedded (via go:embed of mimetypes.json), so the registry is complete and no network or Ruby runtime is required. A Registry answers the same queries the gem exposes on the MIME::Types module:
r := mimetypes.Default()
r.Get("text/html") // []*Type, priority sorted
r.GetRegexp(re) // []*Type matching a content-type pattern
r.TypeFor("index.html") // []*Type by filename extension
r.Of("a.tar.gz") // alias of TypeFor
Each Type mirrors MIME::Type: ContentType, MediaType, SubType, Extensions, PreferredExtension, Friendly, Binary/ASCII, Obsolete, Registered, plus the gem's priority ordering (<=>). The value model is what go-embedded-ruby maps to Ruby MIME::Type objects.
Index ¶
- Constants
- type Registry
- type Type
- func (t *Type) ASCII() bool
- func (t *Type) Binary() bool
- func (t *Type) Complete() bool
- func (t *Type) ContentType() string
- func (t *Type) Docs() string
- func (t *Type) Encoding() string
- func (t *Type) Extensions() []string
- func (t *Type) Friendly() string
- func (t *Type) MediaType() string
- func (t *Type) Obsolete() bool
- func (t *Type) PreferredExtension() string
- func (t *Type) PriorityCompare(other *Type) int
- func (t *Type) Provisional() bool
- func (t *Type) Registered() bool
- func (t *Type) Signature() bool
- func (t *Type) Simplified() string
- func (t *Type) String() string
- func (t *Type) SubType() string
- func (t *Type) UseInstead() string
Constants ¶
const DataVersion = "3.2026.0414"
DataVersion is the version of the embedded mime-types-data registry.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a queryable set of MIME types, mirroring Ruby's MIME::Types.
A Registry is read-only and safe for concurrent use. Use Default for the complete embedded registry, or New to build one from explicit entries.
func Default ¶
func Default() *Registry
Default returns the complete registry built from the embedded mime-types-data dataset. It is parsed once on first use.
func New ¶
New builds a Registry from the given types. The supplied types are indexed by their simplified key and by extension. Insertion order is preserved.
func (*Registry) Get ¶
Get returns the types whose simplified content type matches typeID, priority-sorted. typeID is matched case-insensitively (e.g. "text/html" or "TEXT/HTML"). Mirrors MIME::Types#[] with a string argument.
func (*Registry) GetRegexp ¶
GetRegexp returns every type whose simplified content type matches the pattern, priority-sorted and de-duplicated. Mirrors MIME::Types#[] with a Regexp argument.
func (*Registry) Len ¶
Len reports the number of type variants in the registry. Mirrors MIME::Types#count.
func (*Registry) Of ¶
Of is an alias for Registry.TypeFor, mirroring MIME::Types#of.
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type is a single MIME type entry, mirroring Ruby's MIME::Type.
A Type is immutable once built by the registry; the accessor methods return copies of slices where mutation would otherwise leak into the registry.
func (*Type) ASCII ¶
ASCII reports whether the type is transferred as ASCII (7bit or quoted-printable). Mirrors MIME::Type#ascii?.
func (*Type) Binary ¶
Binary reports whether the type is transferred as binary (base64 or 8bit). Mirrors MIME::Type#binary?.
func (*Type) Complete ¶
Complete reports whether the type carries an extension list. Mirrors MIME::Type#complete?.
func (*Type) ContentType ¶
ContentType returns the raw content type, preserving the registry's casing (e.g. "text/html"). Mirrors MIME::Type#content_type.
func (*Type) Docs ¶
Docs returns the documentation note for this type, or "". Mirrors MIME::Type#docs.
func (*Type) Encoding ¶
Encoding returns the transfer encoding ("base64", "8bit", "7bit" or "quoted-printable"). Mirrors MIME::Type#encoding.
func (*Type) Extensions ¶
Extensions returns the file extensions associated with this type (without a leading dot). Mirrors MIME::Type#extensions.
func (*Type) Friendly ¶
Friendly returns the human-readable English description, or "" if none. Mirrors MIME::Type#friendly (the "en" entry).
func (*Type) MediaType ¶
MediaType returns the simplified, lowercased media type (e.g. "text"). Mirrors MIME::Type#media_type.
func (*Type) Obsolete ¶
Obsolete reports whether the type is obsolete. Mirrors MIME::Type#obsolete?.
func (*Type) PreferredExtension ¶
PreferredExtension returns the preferred file extension. If none was set explicitly, the first extension is used; if there are no extensions, "" is returned. Mirrors MIME::Type#preferred_extension.
func (*Type) PriorityCompare ¶
PriorityCompare orders two types the way MIME::Type#priority_compare (and the gem's #<=>) does: by the precomputed sort priority, then by the simplified representation alphabetically. It returns -1, 0 or 1.
func (*Type) Provisional ¶
Provisional reports whether the type is provisionally registered. Mirrors MIME::Type#provisional?.
func (*Type) Registered ¶
Registered reports whether the type is IANA-registered. Mirrors MIME::Type#registered?.
func (*Type) Signature ¶
Signature reports whether the type is a signature ("magic") type. Mirrors MIME::Type#signature?.
func (*Type) Simplified ¶
Simplified returns the lowercased "media/sub" key. Mirrors MIME::Type#simplified.
func (*Type) SubType ¶
SubType returns the simplified, lowercased sub type (e.g. "html"). Mirrors MIME::Type#sub_type.
func (*Type) UseInstead ¶
UseInstead returns the replacement content type for an obsolete entry, or "" if there is none. Mirrors MIME::Type#use_instead.
