respondwith

package
v0.0.0-...-d28885f Latest Latest
Warning

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

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

Documentation

Overview

Package respondwith contains some helper functions for generating responses in HTTP handlers. Its name is like that because it pairs up with the function names in this package, e.g. "respondwith.ErrorText" or "respondwith.JSON".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorText

func ErrorText(w http.ResponseWriter, err error) bool

ErrorText produces an error response with HTTP status code 500 and Content-Type text/plain if the given error is non-nil. Otherwise, nothing is done and false is returned. Idiomatic usage looks like this:

value, err := thisMayFail()
if respondwith.ErrorText(w, err) {
	return
}

useValue(value)

func JSON

func JSON(w http.ResponseWriter, code int, data any)

JSON serializes the given data into an HTTP response body The `code` argument specifies the HTTP response code, usually 200.

Types

This section is empty.

Jump to

Keyboard shortcuts

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