middleware

package
v0.0.0-...-4231655 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LibraryRequest

type LibraryRequest struct {
	BookID int    `json:"book_id"`
	Type   string `json:"type"`
}

LibraryRequest describes common ADD / DELETE request for user library.

type MW

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

MW defines service which dependent on database.

func New

func New(db *reform.DB, logger *logrus.Logger) *MW

New returns new instance of MW service.

func (*MW) AddToLibrary

func (mw *MW) AddToLibrary(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

AddToLibrary saves given book to the library of current user.

func (*MW) Authorize

func (mw *MW) Authorize(h httprouter.Handle) httprouter.Handle

Authorize middleware: check authorization, save user in context and move request to given handler.

func (*MW) DeleteFromLibrary

func (mw *MW) DeleteFromLibrary(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

DeleteFromLibrary drop given book from the library of current user.

func (*MW) Library

func (mw *MW) Library(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

Library returns the library of current user.

func (*MW) SearchBooks

func (mw *MW) SearchBooks(w http.ResponseWriter, r *http.Request, _ httprouter.Params)

SearchBooks finds multiple books by the given search criteria.

func (*MW) SearchCategories

func (mw *MW) SearchCategories(w http.ResponseWriter, r *http.Request, p httprouter.Params)

func (*MW) SingleBook

func (mw *MW) SingleBook(w http.ResponseWriter, r *http.Request, p httprouter.Params)

SingleBook finds book from database by its id with volumes available for this book.

type Response

type Response struct {
	Data  interface{}    `json:"data,omitempty"`
	Meta  interface{}    `json:"meta,omitempty"`
	Error *ResponseError `json:"error,omitempty"`
}

Response defines common block of API response.

type ResponseError

type ResponseError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ResponseError defines error block of API response.

type SearchBooksRequest

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

SearchBooksRequest describes parameters of books searching request.

type SearchCategoryRequest

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

SearchCategoryRequest describes parameters of categories searching request.

Jump to

Keyboard shortcuts

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