aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAinar Garipov <gugl.zadolbal@gmail.com>2020-09-05 14:24:28 +0300
committerEmmanuel Odeke <emm.odeke@gmail.com>2020-09-06 05:12:37 +0000
commitb60ec4cc4b230f4d0787acf82057947b8bf80cea (patch)
tree0c1053ebcddbadeac41b02ccef9b3abd45c30b9d
parentc489330987eca992cee0bb018a6fdb7ff5401704 (diff)
downloadgo-b60ec4cc4b230f4d0787acf82057947b8bf80cea.tar.gz
go-b60ec4cc4b230f4d0787acf82057947b8bf80cea.zip
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>
-rw-r--r--src/mime/example_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mime/example_test.go b/src/mime/example_test.go
index c7d13cdcdb..85795976f0 100644
--- a/src/mime/example_test.go
+++ b/src/mime/example_test.go
@@ -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
+}