responders

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCanNotEncodeObject should be returned by RespondFunc if the Responder should
	// try a different content type, as we don't know how to respond with this object
	ErrCanNotEncodeObject = errors.New("error can not encode object")
)

Functions

func Data

func Data(w http.ResponseWriter, r *http.Request, v interface{})

Data writes raw bytes to the response, setting the Content-Type as application/octet-stream.

func HTML

func HTML(w http.ResponseWriter, r *http.Request, v interface{}) error

HTML writes a string to the response, setting the Content-Type as text/html.

func JSON

func JSON(w http.ResponseWriter, r *http.Request, v interface{}) error

JSON marshals 'v' to JSON, automatically escaping HTML and setting the Content-Type as application/json.

func PlainText

func PlainText(w http.ResponseWriter, r *http.Request, v interface{}) error

PlainText writes a string to the response, setting the Content-Type as text/plain.

func XML

func XML(w http.ResponseWriter, r *http.Request, v interface{}) error

XML marshals 'v' to XML, setting the Content-Type as application/xml. It will automatically prepend a generic XML header (see encoding/xml.Header) if one is not found in the first 100 bytes of 'v'.

Types

type Func

type Func func(http.ResponseWriter, *http.Request, interface{}) error

Func defined a function that will take an object and Marshal it into a content type before writing it to the http.ResponseWriter

type HTMLMarshaler

type HTMLMarshaler interface {
	MarshalHTML() ([]byte, error)
}

type M

type M map[string]interface{}

M is a convenience alias for quickly building a map structure that is going out to a responder. Just a short-hand.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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