https://github.com/cssivision/media-type
media type parser and formatter(RFC 6838)
https://github.com/cssivision/media-type
format media-type parse
Last synced: 11 months ago
JSON representation
media type parser and formatter(RFC 6838)
- Host: GitHub
- URL: https://github.com/cssivision/media-type
- Owner: cssivision
- License: mit
- Created: 2017-07-31T06:47:50.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-03T03:47:12.000Z (almost 9 years ago)
- Last Synced: 2024-06-20T02:31:53.516Z (almost 2 years ago)
- Topics: format, media-type, parse
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# media-type
[](https://travis-ci.org/cssivision/media-type)
[](https://coveralls.io/github/cssivision/media-type?branch=master)
[](https://github.com/cssivision/media-type/blob/master/LICENSE)
RFC 6838 media type parser.
parse media type into type, subtype, and suffix, or format normal media types string use those parts.
# Installation
```sh
go get github.com/cssivision/media-type
```
# Usage
## parse media type
```go
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)
}
```
## format media type
```go
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)
}
```
# Licenses
All source code is licensed under the [MIT License](https://github.com/cssivision/media-type/blob/master/LICENSE).