render

package
v2.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package render provides HTTP output rendering helper functions.

Index

Constants

View Source
const JSONContentType = "application/json"

JSONContentType represents MIME type for JSON content.

Variables

This section is empty.

Functions

func JSON

func JSON(rw http.ResponseWriter, code int, v any) error

JSON writes a JSON response.

func JSONError

func JSONError(rw http.ResponseWriter, code int, reason string)

JSONError writes a JSON error message.

func JSONErrorf

func JSONErrorf(rw http.ResponseWriter, code int, format string, args ...any)

JSONErrorf writes a JSON error message.

func JSONInternalServerError

func JSONInternalServerError(rw http.ResponseWriter)

JSONInternalServerError writes a JSON internal server error.

Types

type APIError

type APIError struct {
	// Code is the http status code.
	Code int `json:"code"`

	// Error is the reason for the error.
	Error string `json:"error"`
}

APIError contains error information that is rendered by JSONError.

Jump to

Keyboard shortcuts

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