Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

render

v2.0.0+incompatible
github.com/cyx/chi/render

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

23 matches

Top ↑

Constants

ContentTypePlainText (5 declarations)

const (
	ContentTypePlainText = iota
	ContentTypeHTML
	ContentTypeJSON
	ContentTypeXML
	ContentTypeEventStream
)

ContentTypes handled by this package.

Variables

Bind

var Bind = defaultBind

Functions

Data

func Data(w http.ResponseWriter, r *http.Request, v []byte)

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

HTML

func HTML(w http.ResponseWriter, r *http.Request, v string)

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

JSON

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

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

NewPresenter

func NewPresenter(conversionFuncs ...interface{}) *presenter

NoContent

func NoContent(w http.ResponseWriter, r *http.Request)

NoContent returns a HTTP 204 "No Content" response.

PlainText

func PlainText(w http.ResponseWriter, r *http.Request, v string)

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

Respond

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

Respond handles streaming JSON and XML responses, automatically setting the Content-Type based on request headers. It will default to a JSON response.

SetContentType

func SetContentType(contentType ContentType) func(next http.Handler) http.Handler

SetContentType is a middleware that forces response Content-Type.

Status

func Status(r *http.Request, status int)

Status sets status into request context.

UsePresenter

func UsePresenter(p Presenter) func(next http.Handler) http.Handler

UsePresenter is a middleware that sets custom presenter into the context chain.

XML

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

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

ContentType

type ContentType int

A ContentType is an enumeration of common HTTP content types.

Presenter

type Presenter interface {
	Present(r *http.Request, from interface{}) (*http.Request, interface{})
}

Dependency graph