response

package
v0.0.0-...-a839d2f Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 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 Response

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

Response - provide methods for creating responses.

func New

func New(
	writer http.ResponseWriter,
	marshaler types.Marshaler,
	object types.Responser,
) *Response

func (*Response) BadRequest

func (resp *Response) BadRequest(format string, args ...interface{}) error

func (*Response) Created

func (resp *Response) Created() error

func (*Response) Error

func (resp *Response) Error(code int, format string, args ...interface{}) error

func (*Response) Forbidden

func (resp *Response) Forbidden(format string, args ...interface{}) error

func (*Response) InternalServerError

func (resp *Response) InternalServerError(format string, args ...interface{}) error

func (*Response) MethodNotAllowed

func (resp *Response) MethodNotAllowed(format string, args ...interface{}) error

func (*Response) NoContent

func (resp *Response) NoContent() error

func (*Response) NotFound

func (resp *Response) NotFound(format string, args ...interface{}) error

func (*Response) OK

func (resp *Response) OK(payload interface{}) error

func (*Response) Object

func (resp *Response) Object(code int, payload interface{}) error

func (*Response) ResponseWriter

func (resp *Response) ResponseWriter() http.ResponseWriter

func (*Response) WithoutContent

func (resp *Response) WithoutContent(code int) error

type Responser

type Responser interface {
	// ResponseWriter - returns http.ResponseWriter associated with request.
	ResponseWriter() http.ResponseWriter
	// Object - responses with provided custom code and body.
	// Body will be marshaled using service-defined object and marshaler.
	Object(code int, payload interface{}) error
	// WithourContent - responses with provided custom code and no body.
	WithoutContent(code int) error
	// Error - responses custom error with provided code and formatted string message.
	Error(code int, format string, args ...interface{}) error
	// OK - writes payload into json's 'result' field with 200 http code.
	OK(payload interface{}) error
	// Created - responses with 201 http code and no content.
	Created() error
	// NoContent - responses with 204 http code and no content.
	NoContent() error
	// BadRequest - responses with 400 code and provided formatted string message.
	BadRequest(format string, args ...interface{}) error
	// Forbidden - responses with 403 error code and provided formatted string message.
	Forbidden(format string, args ...interface{}) error
	// NotFound - responses with 404 error code and provided formatted string message.
	NotFound(format string, args ...interface{}) error
	// MethodNotAllowed - responses with 405 error code and provided formatted string message.
	MethodNotAllowed(format string, args ...interface{}) error
	// InternalServerError - responses with 500 error code and provided formatted string message.
	InternalServerError(format string, args ...interface{}) error
}

Jump to

Keyboard shortcuts

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