rest

package
v0.0.0-...-65ae5a0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonHandler

type JsonHandler func(r *http.Request) *Response

JsonHandler is a handler that returns a response.

func (JsonHandler) ServeHTTP

func (h JsonHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type Option

type Option func(*Response)

Option is a function that modifies a response.

func SetBody

func SetBody(body interface{}) Option

SetBody will marshal the body to JSON if the content-type is application/json.

func SetStatus

func SetStatus(status int) Option

SetStatus sets the status code of the response.

func SetWrap

func SetWrap(key string) Option

SetWrap will wrap the body in a map with the given key, should be called after SetBody.

func WithError

func WithError(err error) Option

WithError will set the error on the response.

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response is a response from a handler.

func JsonResponse

func JsonResponse(opts ...Option) *Response

JsonResponse returns a response with a content-type of application/json.

func (*Response) Body

func (r *Response) Body() []byte

Body returns the response body.

func (*Response) Error

func (r *Response) Error() error

Error returns the response error.

func (*Response) Header

func (r *Response) Header() http.Header

Header returns the response header.

func (*Response) Status

func (r *Response) Status() int

Status returns the response status code.

Jump to

Keyboard shortcuts

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