handlers

package
v0.0.0-...-a32083c Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

ErrInvalidRequest invalid request

func ErrNotFound

func ErrNotFound() render.Renderer

ErrNotFound not found

Types

type BooksResource

type BooksResource struct {
	Repo interfaces.IBookRepository
}

BooksResource Book router ressources routes

func (*BooksResource) BookCtx

func (rs *BooksResource) BookCtx(next http.Handler) http.Handler

BookCtx build book context and inject `model.Book` into request

func (*BooksResource) Create

func (rs *BooksResource) Create(w http.ResponseWriter, r *http.Request)

Create Add a new book into collection

func (*BooksResource) Delete

func (rs *BooksResource) Delete(w http.ResponseWriter, r *http.Request)

Delete remove a book into your bookshelf by ID

func (*BooksResource) Get

func (rs *BooksResource) Get(w http.ResponseWriter, r *http.Request)

Get get a book by ID

func (*BooksResource) List

func (rs *BooksResource) List(w http.ResponseWriter, r *http.Request)

List Get all books and filter by query string and sorts

func (*BooksResource) Routes

func (rs *BooksResource) Routes() chi.Router

Routes creates a REST router for the books resource

func (*BooksResource) Update

func (rs *BooksResource) Update(w http.ResponseWriter, r *http.Request)

Update update a book

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

ErrResponse renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render render function for error handlers

Jump to

Keyboard shortcuts

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