mime

package module
v0.0.0-...-28bafd7 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 5 Imported by: 2

README

Mime GoDoc

Package for retrieving the mime type given an extension.

Features and limitations

  • Must be given a filename that contains a list of mimetypes followed by extensions. Typically /etc/mime.types.
  • Will only read the file once, then store the lookup table in memory. This results in fast lookups.
  • Has a lookup table for the most common mime types, if no mime information is found.

Example

package main

import (
    "fmt"

    "github.com/xyproto/mime"
)

func main() {
    // Read inn the list of mime types and extensions.
    // Set everything to UTF-8 when writing headers
    m := mime.New("/etc/mime.types", true)

    // Print the mime type for svg.
    fmt.Println(m.Get("svg"))
}
  • Will output: image/svg+xml

General information

  • Version: 0.2.0
  • License: MIT
  • Alexander F Rødseth

Documentation

Overview

Package mime helps retrieving mimetypes given extensions. This is an alternative to the "mime" package, and has fallbacks for the most common types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader caches the contents of a mime info text file

func New

func New(filename string, utf8 bool) *Reader

New creates a new Reader. The filename is a list of mimetypes and extensions. If utf8 is true, "; charset=utf-8" will be added when setting http headers.

func (*Reader) Get

func (mr *Reader) Get(ext string) string

Get returns the mimetype, or an empty string if no mimetype or mimetype source is found

func (*Reader) SetHeader

func (mr *Reader) SetHeader(w http.ResponseWriter, ext string)

SetHeader sets the Content-Type for a given ResponseWriter and filename extension

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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