]> Cypherpunks.ru repositories - gostls13.git/commitdiff
mime: add examples for FormatMediaType and ParseMediaType
authorAinar Garipov <gugl.zadolbal@gmail.com>
Sat, 5 Sep 2020 11:24:28 +0000 (14:24 +0300)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Sun, 6 Sep 2020 05:12:37 +0000 (05:12 +0000)
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>

src/mime/example_test.go

index c7d13cdcdb550c0b284855d04e85a8be6240eaf7..85795976f0914cb22601bdcbbea1db9edb979120 100644 (file)
@@ -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
+}