Skip to content

cssivision/media-type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

media-type

Build Status Coverage Status License

RFC 6838 media type parser. parse media type into type, subtype, and suffix, or format normal media types string use those parts.

Installation

go get github.com/cssivision/media-type

Usage

parse 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)
}

format media type

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.

About

media type parser and formatter(RFC 6838)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages