Skip to content

About

media type parser and formatter(RFC 6838)

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

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

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages