web

package
v0.0.0-...-e29e17f Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2020 License: Apache-2.0, Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInternalServer = errors.New("internal server error")

ErrInternalServer is a generic internal server error.

Functions

func RequestMW

func RequestMW(next http.Handler) http.Handler

RequestMW is a middleware that creates a request id for each request and sets it on the header field X-Request-Id. Also logs the start and end of each request.

func Respond

func Respond(w http.ResponseWriter, r *http.Request, code int, data interface{}, errs ...error)

Respond sends a response with a status code.

func RespondError

func RespondError(w http.ResponseWriter, r *http.Request, code int, err error)

RespondError sends an error response with a status code. The error is automatically logged for you. If the error implements StatusCoder, the provided status code will be used.

Types

type Response

type Response struct {
	Results interface{}     `json:"results,omitempty"`
	Errors  []ResponseError `json:"errors,omitempty"`
}

Response is the format used for all the responses.

type ResponseError

type ResponseError struct {
	Message string `json:"message"`
}

ResponseError is the format used for response errors.

func (ResponseError) Error

func (a ResponseError) Error() string

Error implements the error interface

Jump to

Keyboard shortcuts

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