ext2mime

package module
v0.0.0-...-f8bfdbe Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 2 Imported by: 1

README

go-ext2mime

Package ext2mime provides tools inferring what MIME type is associated with a file extension, for the Go programming language.

For example:

  • .css -> text/css
  • .epub -> application/epub+zip,
  • .html -> text/html,
  • .jpeg -> image/jpeg
  • .js -> text/javascript,
  • .json -> application/json,
  • .md -> text/markdown,
  • .png -> image/png
  • .qoi -> image/qoi
  • etc etc etc.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-ext2mime

GoDoc

Example

Here is a simple example:

import "github.com/reiver/go-ext2mime"

// ...

fileExtension := path.Ext(filename)

mimeType := ext2mime.Get(fileExtension)

You can also add you own file-extension to MIME-type mapping with:

func init() {
	const fileExtension string = ".abc"
	const mimeType string = "application/abc"

	ext2mime.Set(fileExtension, mimeType)
}

Import

To import package ext2mime use import code like the follownig:

import "github.com/reiver/go-ext2mime"

Installation

To install package ext2mime do the following:

GOPROXY=direct go get https://github.com/reiver/go-ext2mime

Author

Package ext2mime was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(fileExtension string) (string, bool)

func Set

func Set(fileExtension string, mimeType string) error

Types

type Mapping

type Mapping struct {
	// contains filtered or unexported fields
}
var Default Mapping

func (*Mapping) Get

func (receiver *Mapping) Get(fileExtension string) (mimeType string, found bool)

func (*Mapping) Set

func (receiver *Mapping) Set(fileExtension string, mimeType string) error

Jump to

Keyboard shortcuts

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