Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Names is a map of content type names to content type values. Names = map[ContentType]string{ Form: "application/x-www-form-urlencoded", Html: "text/html", Json: "application/json", MsgPack: "application/msgpack", Text: "text/plain", Yaml: "application/yaml", } // Set is a map of content type values to content type marshal and unmarshal. Set = map[ContentType]IContentType{ Form: &FormType{}, Html: &HtmlType{}, Json: &JsonType{}, MsgPack: &MsgPackType{}, Text: &TextType{}, Yaml: &YamlType{}, } // ErrInvalid is returned when the content type is invalid. ErrInvalid = errors.New("invalid content type") )
Functions ¶
This section is empty.
Types ¶
type ContentType ¶
type ContentType uint8
ContentType is a content type.
const ( Invalid ContentType = iota Form Html Json MsgPack Text Yaml )
func MustParse ¶
func MustParse(name string) ContentType
MustParse parses content type string or panics.
func (ContentType) MarshalJSON ¶
func (ct ContentType) MarshalJSON() ([]byte, error)
MarshalJSON content type to json
func (*ContentType) UnmarshalJSON ¶
func (ct *ContentType) UnmarshalJSON(b []byte) error
UnmarshalJSON content type from json
type FormType ¶
type FormType struct{}
FormType is a form type.
type HtmlType ¶
type HtmlType struct{}
HtmlType is a html type.
type IContentType ¶
type IContentType interface { // Marshal marshals the value to a reader. Marshal(any) (io.Reader, error) // Unmarshal unmarshals the reader to a value. Unmarshal(io.Reader, any) error }
IContentType is a content type interface.
type JsonType ¶
type JsonType struct{}
JsonType is a json type.
type MsgPackType ¶
type MsgPackType struct{}
MsgPackType is a msgpack type.
type TextType ¶
type TextType struct{}
TextType is a text type.
Click to show internal directories.
Click to hide internal directories.