web

package
v0.0.0-...-9f32554 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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"`
	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