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
Click to show internal directories.
Click to hide internal directories.