response

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 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 Option added in v0.0.16

type Option func(*Response)

Option helps overriding/adding response options to the current response.

func Code added in v0.0.16

func Code(code int) Option

Code sets status code.

func Error

func Error(action string, message string, errors map[string]string) Option

Error represents "failure" response.

func Headers added in v0.0.16

func Headers(headers map[string]string) Option

Headers adds headers.

func Success

func Success(action string, data interface{}, meta interface{}) Option

Success represents "successful" response.

type Response added in v0.0.16

type Response struct {
	Action  string            `json:"action,omitempty"`
	Data    interface{}       `json:"data,omitempty"`
	Meta    interface{}       `json:"meta,omitempty"`
	Message string            `json:"message,omitempty"`
	Errors  map[string]string `json:"errors,omitempty"`
	// contains filtered or unexported fields
}

func New added in v0.0.16

func New(opts ...Option) Response

New creates and returns a new `Response` instance. All the arguments can be overridden by passing variadic `opts` ("Functional Options") arguments. If no options are given, an empty `200` response is used.

func (Response) Write added in v0.0.16

func (r Response) Write(w http.ResponseWriter) error

Write sends the response to the client.

Jump to

Keyboard shortcuts

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