render

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package render implements functionality related to response rendering.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(w http.ResponseWriter, err error)

Error marshals the JSON representation of err to w. In case err implements RenderableError its own Render method will be called instead.

func JSON

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

JSON is shorthand for JSONStatus(w, v, http.StatusOK).

func JSONStatus

func JSONStatus(w http.ResponseWriter, v interface{}, status int)

JSONStatus marshals v into w. It additionally sets the status code of w to the given one.

JSONStatus sets the Content-Type of w to application/json unless one is specified.

func ProtoJSON

func ProtoJSON(w http.ResponseWriter, m proto.Message)

ProtoJSON is shorthand for ProtoJSONStatus(w, m, http.StatusOK).

func ProtoJSONStatus

func ProtoJSONStatus(w http.ResponseWriter, m proto.Message, status int)

ProtoJSONStatus writes the given value into the http.ResponseWriter and the given status is written as the status code of the response.

Types

type RenderableError

type RenderableError interface {
	error

	Render(http.ResponseWriter)
}

RenderableError is the set of errors that implement the basic Render method.

Errors that implement this interface will use their own Render method when being rendered into responses.

type StatusCodedError

type StatusCodedError interface {
	error

	StatusCode() int
}

StatusCodedError is the set of errors that implement the basic StatusCode function.

Errors that implement this interface will use the code reported by StatusCode as the HTTP response code when being rendered by this package.

Jump to

Keyboard shortcuts

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