RFC 6838 media type parser. parse media type into type, subtype, and suffix, or format normal media types string use those parts.
go get github.com/cssivision/media-type
package main
import (
"fmt"
mediaType "github.com/cssivision/media-type"
)
func main() {
mt, err := mediaType.Parse("application/json+xml")
if err != nil {
panic(err)
}
fmt.Println("type: ", mt.Type)
fmt.Println("subtype: ", mt.SubType)
fmt.Println("suffix: ", mt.Suffix)
}
package main
import (
"fmt"
mediaType "github.com/cssivision/media-type"
)
func main() {
mt := &mediaType.MediaType{
Type: "application",
SubType: "json",
Suffix: "xml",
}
str, err := mt.Format()
if err != nil {
panic(err)
}
fmt.Println("media type:", str)
}
All source code is licensed under the MIT License.