mirror of
https://github.com/golang/go.git
synced 2024-09-22 10:58:58 +00:00
mime: add examples for FormatMediaType and ParseMediaType
Change-Id: Ic129c58784ad1f0b8b90fc9d33e52bee61bdf0eb Reviewed-on: https://go-review.googlesource.com/c/go/+/253237 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c489330987
commit
b60ec4cc4b
@ -96,3 +96,29 @@ func ExampleWordDecoder_DecodeHeader() {
|
||||
// ¡Hola, señor!
|
||||
// HELLO WORLD!
|
||||
}
|
||||
|
||||
func ExampleFormatMediaType() {
|
||||
mediatype := "text/html"
|
||||
params := map[string]string{
|
||||
"charset": "utf-8",
|
||||
}
|
||||
|
||||
result := mime.FormatMediaType(mediatype, params)
|
||||
|
||||
fmt.Println("result:", result)
|
||||
// Output:
|
||||
// result: text/html; charset=utf-8
|
||||
}
|
||||
|
||||
func ExampleParseMediaType() {
|
||||
mediatype, params, err := mime.ParseMediaType("text/html; charset=utf-8")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("type:", mediatype)
|
||||
fmt.Println("charset:", params["charset"])
|
||||
// Output:
|
||||
// type: text/html
|
||||
// charset: utf-8
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user