Skip to content

Commit b60ec4c

Browse files
ainar-godeke-em
authored andcommitted
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>
1 parent c489330 commit b60ec4c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/mime/example_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,29 @@ func ExampleWordDecoder_DecodeHeader() {
9696
// ¡Hola, señor!
9797
// HELLO WORLD!
9898
}
99+
100+
func ExampleFormatMediaType() {
101+
mediatype := "text/html"
102+
params := map[string]string{
103+
"charset": "utf-8",
104+
}
105+
106+
result := mime.FormatMediaType(mediatype, params)
107+
108+
fmt.Println("result:", result)
109+
// Output:
110+
// result: text/html; charset=utf-8
111+
}
112+
113+
func ExampleParseMediaType() {
114+
mediatype, params, err := mime.ParseMediaType("text/html; charset=utf-8")
115+
if err != nil {
116+
panic(err)
117+
}
118+
119+
fmt.Println("type:", mediatype)
120+
fmt.Println("charset:", params["charset"])
121+
// Output:
122+
// type: text/html
123+
// charset: utf-8
124+
}

0 commit comments

Comments
 (0)