Standard library / mime
mime.FormatMediaType()
Serialize a media type and parameters with suitable quoting; invalid input yields an empty string. Expected stdout: 'text/plain; charset=utf-8; name="a b"\n'.
Formal Syntax & Structure
go syntaxgo
func FormatMediaType(t string, param map[string]string) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| t | string | Media type token or type/subtype. |
| param | map[string]string | Map of media-type parameter names to values. |
Return Value
string
Serialized type and parameters, or empty string for invalid input.
Working Example
Example Snippetgo
package main
import ( "fmt" "mime")
func main() { fmt.Println(mime.FormatMediaType("TEXT/PLAIN", map[string]string{"charset": "utf-8", "name": "a b"}))}
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) }}