web

package
v0.0.0-...-dc1fdd5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const KeyValues ctxKey = 1

KeyValues is how request values or stored/retrieved.

Variables

View Source
var (
	// ErrNotAuthorized occurs when the call is not authorized.
	ErrNotAuthorized = errors.New("Not authorized")

	// ErrDBNotConfigured occurs when the DB is not initialized.
	ErrDBNotConfigured = errors.New("DB not initialized")

	// ErrNotFound is abstracting the mgo not found error.
	ErrNotFound = errors.New("Entity not found")

	// ErrInvalidID occurs when an ID is not in a valid form.
	ErrInvalidID = errors.New("ID is not in it's proper form")

	// ErrValidation occurs when there are validation errors.
	ErrValidation = errors.New("Validation errors occurred")

	// ErrInvalidInput occurs when the input data is invalid
	ErrInvalidInput = errors.New("Invalid input data")

	// ErrEntityTooLarge occurs when the input data is invalid
	ErrEntityTooLarge = errors.New("Request entity too large")
)

Functions

func Error

func Error(ctx context.Context, writer http.ResponseWriter, err error)

Error handles all error responses for the API.

func Respond

func Respond(ctx context.Context, writer http.ResponseWriter, data interface{}, code int)

Respond sends JSON to the client. If code is StatusNoContent, v is expected to be nil.

func RespondError

func RespondError(ctx context.Context, writer http.ResponseWriter, err error, code int)

RespondError sends JSON describing the error

Types

type ContextValues

type ContextValues struct {
	TraceID    string
	Method     string
	RequestURI string
	ID         string
}

ContextValues contains information about request URI and method

type Handler

Handler is a type that handles a http request

func (Handler) ServeHTTP

func (fn Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP interface is implemented by Handler

type JSONError

type JSONError struct {
	Error string `json:"error"`
}

JSONError is the response for errors that occur within the API. swagger:response internalError

type Middleware

type Middleware func(Handler) Handler

A Middleware is a type that wraps a handler to remove boilerplate or other concerns not direct to any given Handler.

Jump to

Keyboard shortcuts

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