contenttype

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MPL-2.0 Imports: 10 Imported by: 0

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 Parse

func Parse(name string) ContentType

Parse parses content type string.

func (ContentType) MarshalJSON

func (ct ContentType) MarshalJSON() ([]byte, error)

MarshalJSON content type to json

func (ContentType) String

func (ct ContentType) String() string

String content type to string

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.

func (*FormType) Marshal

func (ft *FormType) Marshal(value any) (io.Reader, error)

Marshal returns a reader for the given value.

func (*FormType) Unmarshal

func (ft *FormType) Unmarshal(r io.Reader, value any) error

Unmarshal parses the given reader and stores the result in the value pointed to by value.

type HtmlType

type HtmlType struct{}

HtmlType is a html type.

func (*HtmlType) Marshal

func (ht *HtmlType) Marshal(value any) (io.Reader, error)

Marshal returns a reader for the given value.

func (*HtmlType) Unmarshal

func (ht *HtmlType) Unmarshal(r io.Reader, value any) error

Unmarshal parses the given reader and stores the result in the value pointed to by value.

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.

func (*JsonType) Marshal

func (jt *JsonType) Marshal(value any) (io.Reader, error)

Marshal returns a reader for the given value.

func (*JsonType) Unmarshal

func (jt *JsonType) Unmarshal(r io.Reader, value any) error

Unmarshal parses the given reader and stores the result in the value pointed to by value.

type MsgPackType

type MsgPackType struct{}

MsgPackType is a msgpack type.

func (*MsgPackType) Marshal

func (mt *MsgPackType) Marshal(value any) (io.Reader, error)

Marshal returns a reader for the given value.

func (*MsgPackType) Unmarshal

func (mt *MsgPackType) Unmarshal(r io.Reader, value any) error

Unmarshal parses the given reader and stores the result in the value pointed to by value.

type TextType

type TextType struct{}

TextType is a text type.

func (*TextType) Marshal

func (tt *TextType) Marshal(value any) (io.Reader, error)

Marshal returns a reader for the given value.

func (*TextType) Unmarshal

func (tt *TextType) Unmarshal(r io.Reader, value any) error

Unmarshal parses the given reader and stores the result in the value pointed to by value.

type YamlType

type YamlType struct{}

YamlType is a yaml type.

func (*YamlType) Marshal

func (yt *YamlType) Marshal(value any) (io.Reader, error)

Marshal returns a reader for the given value.

func (*YamlType) Unmarshal

func (yt *YamlType) Unmarshal(r io.Reader, value any) error

Unmarshal parses the given reader and stores the result in the value pointed to by value.

Jump to

Keyboard shortcuts

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