rest

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadContentType is returned when a request has a bad content type.
	ErrBadContentType = NewError("bad content type", http.StatusUnsupportedMediaType)
	// ErrBadRequest is returned when a request is bad.
	ErrBadRequest = NewError("bad request", http.StatusBadRequest)
	// ErrEmptyBody is returned when a request has an empty body.
	ErrEmptyBody = NewError("empty body", http.StatusBadRequest)
	// ErrForbidden is returned when a request is forbidden.
	ErrForbidden = NewError("forbidden", http.StatusForbidden)
	// ErrInternal is returned when an internal error occurs.
	ErrInternal = NewError("internal error", http.StatusInternalServerError)
	// ErrNotFound is returned when a resource is not found.
	ErrNotFound = NewError("not found", http.StatusNotFound)
	// ErrNotSupported is returned when a method is not supported.
	ErrNotSupported = NewError("not supported", http.StatusMethodNotAllowed)
	// ErrUnauthorized is returned when a request is unauthorized.
	ErrUnauthorized = NewError("unauthorized", http.StatusUnauthorized)
	// ErrConflict is returned when a request causes a conflict.
	ErrConflict = NewError("conflict", http.StatusConflict)
)

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	// Method is the HTTP method of the endpoint.
	Method map[string]Handler
}

Endpoint is the specification of a REST endpoint.

func (*Endpoint) ServeHTTP

func (e *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type Error

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

Error is an error from an endpoint.

func NewError

func NewError(message string, statusCode int) *Error

NewError returns a new Error.

func (*Error) Cause

func (e *Error) Cause() error

Cause returns the cause of the error.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

func (*Error) Is

func (e *Error) Is(target error) bool

Is implements the errors.Is interface.

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode implements the StatusCode interface.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap implements the errors.Unwrap interface.

func (*Error) WithCause

func (e *Error) WithCause(cause error) *Error

WithCause returns a new Error with the given cause.

type ErrorResponse

type ErrorResponse struct {
	// Error is the error.
	Error string `json:"error"`
}

ErrorResponse is a response that contains an error.

type Handler

type Handler struct {
	// NewRequest returns a new request for the handler.
	NewRequest func() Request
	// Handle handles the request.
	Handle Implementation
}

Handler is a REST handler.

type Implementation

type Implementation func(context.Context, Request) Response

Implementation is the implementation of a REST endpoint.

type Request

type Request interface{}

Request is a REST request.

type Response

type Response interface{}

Response is a REST response.

type StatusCode

type StatusCode interface {
	// StatusCode returns the status code of the response.
	StatusCode() int
}

StatusCode is implemented by Responses that have a status code.

type Validate

type Validate interface {
	// Validate validates the request.
	Validate() error
}

Validate is implemented by Requests that can be validated.

Jump to

Keyboard shortcuts

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