Standard library / mime

mime.AddExtensionType()

Register an extension-to-media-type mapping in this process. Registration does not inspect file bytes. Expected stdout: 'application/x-bytemind36\n'.

Formal Syntax & Structure

go syntaxgo
func AddExtensionType(ext, typ string) error

Parameters & Attributes

NameTypeDescription
extstringFile extension including the leading dot.
typstringMedia type to associate or look up.

Return Value

error

Nil on success, otherwise the operation error.

Working Example

Example Snippetgo
package main
import (  "fmt"  "mime")
func main() {  check(mime.AddExtensionType(".bytemind36", "application/x-bytemind36"))  fmt.Println(mime.TypeByExtension(".bytemind36"))}
func must[T any](v T, e error) T {  if e != nil {    panic(e)  }  return v}func check(e error) {  if e != nil {    panic(e)  }}
Go Reference