mime

package
v0.0.0-...-f6c12a3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2024 License: Apache-2.0 Imports: 1 Imported by: 3

README

What

Static content-type ("MIME") database.

To update the database

Run:

$ go generate ./generator

This updates and code generates our db.gen.go from the source's head. Remember to $ go fmt before committing.

Source of data

flowchart TD
    IANA -- aggregated to --> mimedb
    Apache -- aggregated to --> mimedb
    NGINX -- aggregated to --> mimedb
    mimedb["jshttp/mime-db"] -- uses / exposes --> gokit["gokit/mime"]

See more

Why?

Go's stdlib

Go's built-in DB relies on OS to provide it. It works differently on Windows, Linux etc.

On Alpine Linux IIRC there isn't a package to supply the database, unless you install Apache or Nginx.

Go's ecosystem

https://github.com/cubewise-code/go-mime

  • TypeByExtension() doesn't have fallback
  • there is no ExtensionByType()

https://github.com/gabriel-vasile/mimetype

  • Based on magic numbers

https://github.com/h2non/filetype

  • Based on magic numbers

Documentation

Overview

MIME (Content Type) database. The stdlib MIME package relies on OS to have the list, so the results are inconsistent (f.ex. on stock Alpine Linux it doesn't even recognize JSON)

Index

Constants

View Source
const (
	OctetStream = "application/octet-stream"
	NoFallback  = ""
)

Variables

This section is empty.

Functions

func ExtensionByType

func ExtensionByType(contentType string, fallback string) string

image/jpeg => jpg

func Is

func Is(contentType string, typ Type) bool

Is("image/jpeg", TypeImage) => true Is("text/plain", TypeImage) => false

func TypeByExtension

func TypeByExtension(ext string, fallback string) string

Supports: - ".json" - "json" - "JSON" - "JsOn"

Types

type Spec

type Spec struct {
	Extensions   []string `json:"extensions"`
	Compressible *bool    `json:"compressible"` // nil if unknown
	CharEncoding string   `json:"charset"`      // not always recorded
	Source       string   `json:"source"`
}

JSON tags are defined due to importing in code generation phase, but please do not rely on those (don't JSON-marshal this spec)

type Type

type Type string
const (
	TypeApplication Type = "application"
	TypeAudio       Type = "audio"
	TypeExample     Type = "example"
	TypeFont        Type = "font"
	TypeImage       Type = "image"
	TypeMessage     Type = "message"
	TypeModel       Type = "model"
	TypeMultipart   Type = "multipart"
	TypeText        Type = "text"
	TypeVideo       Type = "video"
)

taken from https://en.wikipedia.org/wiki/Media_type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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