responder

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 6 Imported by: 4 modules, 7 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Responder

type Responder struct{}

Responder is responsible for responding to http requests, providing methods for responding in with JSON and handling errors

func New

func New() *Responder

New returns a new responder

func (*Responder) Bytes

func (r *Responder) Bytes(ctx context.Context, w http.ResponseWriter, status int, resp []byte)

Bytes responds to a http request with the raw bytes of whatever's passed as resp. Can be used to respond with a raw string, bytes, pre-encoded object etc

func (*Responder) Error

func (r *Responder) Error(ctx context.Context, w http.ResponseWriter, status int, err error)

Error responds with a single error, formatted to fit in ONS's desired error response structure (essentially an array of errors)

func (*Responder) Errors

func (r *Responder) Errors(ctx context.Context, w http.ResponseWriter, status int, errs []error)

Errors responds with a slice of errors formatted to ONS's desired error response structure. Note you will have to pass a slice of []error rather than slice of []{some type that implements error}. The underlying structs can be any type that implements error but the slice itself must be defined as []error

func (*Responder) JSON

func (r *Responder) JSON(ctx context.Context, w http.ResponseWriter, status int, resp interface{})

JSON responds to a HTTP request, expecting the response body to be marshall-able into JSON

func (*Responder) StatusCode

func (r *Responder) StatusCode(w http.ResponseWriter, status int)

StatusCode responds with a raw status code

Directories

Path Synopsis
examples
basic_handler command

Jump to

Keyboard shortcuts

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