Standard library / mime
mime.TypeByExtension()
Look up an extension in the MIME database; a missing mapping returns empty. This is a hint, not content validation. Expected stdout: 'application/x-bytemind36\n'.
Formal Syntax & Structure
go syntaxgo
func TypeByExtension(ext string) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| ext | string | File extension including the leading dot. |
Return Value
string
Registered media type, or empty string if unknown.
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) }}