Documentation ¶
Index ¶
- func ErrInvalidRequest(err error) render.Renderer
- func ErrNotFound() render.Renderer
- type BooksResource
- func (rs *BooksResource) BookCtx(next http.Handler) http.Handler
- func (rs *BooksResource) Create(w http.ResponseWriter, r *http.Request)
- func (rs *BooksResource) Delete(w http.ResponseWriter, r *http.Request)
- func (rs *BooksResource) Get(w http.ResponseWriter, r *http.Request)
- func (rs *BooksResource) List(w http.ResponseWriter, r *http.Request)
- func (rs *BooksResource) Routes() chi.Router
- func (rs *BooksResource) Update(w http.ResponseWriter, r *http.Request)
- type ErrResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrInvalidRequest ¶
ErrInvalidRequest invalid request
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