Standard library / mime
mime.ParseMediaType()
Parse a Content-Type or Content-Disposition value. Type and parameter keys are normalized to lowercase; values retain case. Check the error before using the parameters. Expected stdout: 'text/plain UTF-8\n'.
Formal Syntax & Structure
go syntaxgo
func ParseMediaType(v string) (mediatype string, params map[string]string, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| v | string | Media type and optional parameters to parse. |
Return Value
(mediatype string, params map[string]string, err error)
Lowercased media type, parameter map, and parsing error.
Working Example
Example Snippetgo
package main
import ( "fmt" "mime")
func main() { t, p, e := mime.ParseMediaType("Text/Plain; Charset=UTF-8") check(e) fmt.Println(t, p["charset"])}
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) }}