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) string

Parameters & Attributes

NameTypeDescription
tstringMedia type token or type/subtype.
parammap[string]stringMap 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)  }}
Go Reference