An [Internet] Media Type and MIME string parser and modeler for Go
This library expands on the builtin "mime" package to provide a model for an "Internet Media Type" normally specified by Content-Type
HTTP and MIME header fields, and as specified in RFC 2045.
go get github.com/Rican7/mediatype
contentTypeString := "application/vnd.google-earth.kml+xml; charset=utf-8"
mediaType, _ := mediatype.Parse(contentTypeString)
mediaType.MainType() // "application"
mediaType.SubType() // "kml"
mediaType.Trees() // ["vnd", "google-earth"]
mediaType.Prefix() // "vnd"
mediaType.Suffix() // "xml"
mediaType.Parameters() // ["charset": "utf-8"]
mediaType.FullType() // "application/vnd.google-earth.kml+xml"
mediaType.String() // "application/vnd.google-earth.kml+xml; charset=utf-8"
mutable := &mediatype.Mutable{
Main: "application",
Sub: "json",
}
mutable.String() // "application/json"
mutable.Sub = "xhtml"
mutable.Suffix = "xml"
mutable.String() // "application/xhtml+xml"
immutable := mutable.Immutable()
mutable.Main = "image"
immutable.String() // "application/xhtml+xml"