responder

package
v3.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 6 Imported by: 0

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

Jump to

Keyboard shortcuts

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