httpresponse

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 9 modules, 57 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ContentTypeKey   = "Content-Type"
	ContentLengthKey = "Content-Length"
	ContentTypeJSON  = "application/json"
	ContentTypeText  = "text/plain"
)

Variables

This section is empty.

Functions

func Empty

func Empty(w http.ResponseWriter, code int)

Empty is a utility function to serve an empty response

func Error

func Error(w http.ResponseWriter, code int, reason ...string) error

Error is a utility function to serve a JSON error notice

func JSON

func JSON(w http.ResponseWriter, v interface{}, code int, indent uint) error

JSON is a utility function to serve an arbitary object as JSON

func Text added in v1.4.2

func Text(w http.ResponseWriter, v string, code int)

Text is a utility function to serve plaintext

Types

type ErrorResponse added in v1.4.2

type ErrorResponse struct {
	Code   int    `json:"code"`
	Reason string `json:"reason,omitempty"`
}

ErrorResponse is a generic error response which is served as JSON using the ServeError method

Jump to

Keyboard shortcuts

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