httpresponse

package
v1.4.7 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 3 Imported by: 1

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

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

Text is a utility function to serve plaintext

Types

type ErrorResponse

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