mimetypes

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2019 License: MIT Imports: 5 Imported by: 1

README

mimetypes

godoc

travis-ci

A simple library for parsing Apache-style mime.types / XDG-defined media type globs.

This library was created to overcome the limitation of the implementation of mime package, which takes it for granted that an apache-style mime type file is installed in any of the hard-coded locations as for Unix-like platform.

Usage

Be sure to import github.com/moriyoshi/mimetypes/loaders if you want to use the default loader implementations, like the following:

import (
    _ "github.com/moriyoshi/mimetypes/loaders"
)

This ensures the default loaders to be compiled and incorporated into the build.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLoader

func AddLoader(format string, loader Loader)

Types

type BasicMediaTypeRegistry

type BasicMediaTypeRegistry struct {
	ExtToType      map[string]*InternalMediaType
	ExactToType    map[string]*InternalMediaType
	PatternsToType []*InternalMediaType
	NameToType     map[string]*InternalMediaType
}

BasicMediaTypeRegistry provides the basic implentation of MediaTypeRegistry.

func NewBasicMediaTypeRegistry

func NewBasicMediaTypeRegistry() *BasicMediaTypeRegistry

func (*BasicMediaTypeRegistry) Add

func (mtr *BasicMediaTypeRegistry) Add(mt MediaType)

Add() adds a new MediaType to the registry.

func (*BasicMediaTypeRegistry) ExtensionsByType

func (mtr *BasicMediaTypeRegistry) ExtensionsByType(typ string) ([]string, error)

func (*BasicMediaTypeRegistry) TypeByExtension

func (mtr *BasicMediaTypeRegistry) TypeByExtension(ext string) string

func (*BasicMediaTypeRegistry) TypeByFilename

func (mtr *BasicMediaTypeRegistry) TypeByFilename(name string) string

type InternalMediaType

type InternalMediaType struct {
	MediaType
	Extensions []string
}

type Loader

type Loader func(io.Reader) (MediaTypeRegistry, error)

type MediaType

type MediaType struct {
	Name  string
	Globs []string
}

MediaType represents a single media type designation

type MediaTypeRegistry

type MediaTypeRegistry interface {
	ExtensionsByType(string) ([]string, error)
	TypeByExtension(string) string
	TypeByFilename(string) string
}

func Load

func Load(path, format string) (MediaTypeRegistry, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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