You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.2 KiB

package mime_test
import (
"encoding/json"
"fmt"
"gitoa.ru/go-4devs/mime"
)
func ExampleMime_String() {
fmt.Printf("%v", mime.TextHTML)
// Output:
// text/html
}
func ExampleMime_Is() {
fmt.Printf("%v\n%v",
mime.TextHTML.Is(mime.ApplicationJSON, mime.ApplicationJavascript),
mime.TextHTML.Is(mime.ApplicationJavascript, mime.TextHTML),
)
// Output:
// false
// true
}
func ExampleMime_ExtTypes() {
fmt.Printf("%v\n%v",
mime.TextHTML.ExtTypes(),
mime.ApplicationJavascript.ExtTypes(),
)
// Output:
// [html htm shtml]
// [js mjs jsm]
}
func ExampleMime_jsonUnmarshal() {
type Expect struct {
Data string `json:"data"`
Mime mime.Mime `json:"mime"`
}
var res Expect
_ = json.Unmarshal([]byte(`{"data":"text","mime":"text/html"}`), &res)
fmt.Printf("%[1]v: %[1]T(%#[1]v)", res.Mime)
// Output:
// text/html: mime.Mime(1406)
}
func ExampleMime_jsonMarshal() {
type Expect struct {
Data string `json:"data"`
Mime mime.Mime `json:"mime"`
}
res := Expect{
Data: "some text",
Mime: mime.TextMarkdown,
}
result, err := json.Marshal(res)
fmt.Printf("%s\n%v", result, err)
// Output:
// {"data":"some text","mime":"text/markdown"}
// <nil>
}