web

package
v0.0.0-...-d0cd436 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteJSON

func WriteJSON(w http.ResponseWriter, code int, content any)

WriteJSON writes a JSON encoded response.

func WriteJSONErr

func WriteJSONErr[T ~string | ~[]string | ErrorResponse](w http.ResponseWriter, code int, payload T)

WriteJSONErr writes a JSON encoded error message.

Depending on the payload type, different kind of error is assumed.

func WriteJSONStdErr

func WriteJSONStdErr(w http.ResponseWriter, code int)

WriteJSONStdErr writes a JSON encoded error response with a standard for the given response code summary text.

Types

type ErrorResponse

type ErrorResponse struct {
	// Code is the repeated HTTP response code, to make the introspection
	// by humans more pleasant.
	Code int `json:"code"`

	// Summary is a human readable decription of the issue.
	Summary string `json:"error"`

	// Issues represents a list of problems encountered during the
	// processing of the request. For example, a list of incoming data
	// validation errors.
	Issues []string `json:"issues,omitempty"`
}

ErrorResponse represents an error response commonly used by this package.

func (*ErrorResponse) Error

func (err *ErrorResponse) Error() string

func (*ErrorResponse) String

func (err *ErrorResponse) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳