response

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// HTMLEngineCtxKey is the context.Context key to store the request context.
	HTMLEngineCtxKey = &contextKey{"HTMLEngine"}
)

Functions

func Data

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

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, status int, name string, v any)

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

func JSON

func JSON(w http.ResponseWriter, r *http.Request, status int, v any)

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

func NoContent

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

NoContent returns a HTTP 204 "No Content" response.

func PureJSON added in v1.0.2

func PureJSON(w http.ResponseWriter, r *http.Request, status int, v any)

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

func Text added in v1.0.2

func Text(w http.ResponseWriter, r *http.Request, status int, v string)

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

func XML

func XML(w http.ResponseWriter, r *http.Request, status int, v any)

XML marshals 'v' to JSON, 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 ExecuteTemplate added in v1.0.2

type ExecuteTemplate interface {
	ExecuteTemplate(w io.Writer, name string, data any) error
}

func HTMLEngine added in v1.0.2

func HTMLEngine(ctx context.Context) ExecuteTemplate

type M

type M map[string]any

type S added in v1.0.2

type S []any

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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