formats

package
v0.0.0-...-c5b96c6 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const FormResourceType string = "application/x-www-form-urlencoded"
View Source
const JSONResourceType string = "application/json"
View Source
const XMLResourceType string = "application/xml"
View Source
const YAMLResourceType string = "application/yaml"

Variables

View Source
var DefaultRequestFormatter = JSONResourceType

DefaultRequestFormatter defines the default decoding in the absence of headers

View Source
var DefaultResponseFormatter = JSONResourceType

DefaultResponseFormatter defines the default encoding in the absence of headers

Functions

func BindFormatter

func BindFormatter(t string, f Formatter)

BindFormatter Bind an alternate formatter implementation

func Decode

func Decode(t string, r *http.Request, i interface{}) error

Decode Generic decode function (uses http accept header)

func Encode

func Encode(accepts string, i interface{}) (string, string, error)

Encode Generic encode function

func ParseAcceptHeader

func ParseAcceptHeader(accept string) []string

ParseAcceptHeader Parses an HTTP accept header to return an ordered list of content types

func RemoveFormatter

func RemoveFormatter(t string)

RemoveFormatter Remove a formatter implementation

Types

type Form

type Form struct {
}

func NewForm

func NewForm() Form

func (Form) Decode

func (j Form) Decode(r *http.Request, i interface{}) error

func (Form) Encode

func (j Form) Encode(o interface{}) (string, error)

type Formatter

type Formatter interface {
	Encode(o interface{}) (string, error)
	Decode(r *http.Request, i interface{}) error
}

Formatter Defines a formatter interface

type JSON

type JSON struct {
}

func NewJSON

func NewJSON() JSON

func (JSON) Decode

func (j JSON) Decode(r *http.Request, i interface{}) error

func (JSON) Encode

func (j JSON) Encode(o interface{}) (string, error)

type XML

type XML struct {
}

func NewXML

func NewXML() XML

func (XML) Decode

func (j XML) Decode(r *http.Request, i interface{}) error

func (XML) Encode

func (j XML) Encode(o interface{}) (string, error)

type YAML

type YAML struct {
}

func NewYAML

func NewYAML() YAML

func (YAML) Decode

func (j YAML) Decode(r *http.Request, i interface{}) error

func (YAML) Encode

func (j YAML) Encode(o interface{}) (string, error)

Jump to

Keyboard shortcuts

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