mediaType

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2017 License: MIT Imports: 3 Imported by: 0

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MediaType

type MediaType struct {
	Type       string
	SubType    string
	Suffix     string
	Parameters map[string]string
}

MediaType mediaType object.

func Parse

func Parse(str string) (*MediaType, error)

Parse parse media type to object.

func (*MediaType) Format

func (mt *MediaType) Format() (string, error)

Format format object to media type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL