rest

package
v0.0.0-...-8227220 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDecoding = errors.New("error decoding data from request")
View Source
var ErrEncoding = errors.New("error encoding data to buffer")
View Source
var ErrInvalidData = errors.New("invalid data, expected nil")
View Source
var ErrInvalidQuery = errors.New("invalid query")
View Source
var ErrNotAuthorized = errors.New("not authorized")
View Source
var ErrPermissions = errors.New("error permissions")
View Source
var ErrWritingResponse = errors.New("error writing response from buffer")

Functions

func ChainMiddlewares

func ChainMiddlewares(hdl http.Handler, mds ...func(http.Handler) http.Handler) http.Handler

func WithContextKey

func WithContextKey(key any, val any) func(http.Handler) http.Handler

WithContextKey wraps key/val pairs into request context.

func WithLogRequest

func WithLogRequest(logger models.Logger) func(http.Handler) http.Handler

WithLogRequest logs every request and sends logger instance to further handler.

func WithoutPanic

func WithoutPanic(logger models.Logger) func(http.Handler) http.Handler

WithoutPanic recovers from panic.

Types

type Book

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

func NewBook

func NewBook(logic BookLogic, logger models.Logger) Book

func (Book) AddToFavorites

func (b Book) AddToFavorites(rw http.ResponseWriter, req *http.Request)

func (Book) AddToWishlist

func (b Book) AddToWishlist(rw http.ResponseWriter, req *http.Request)

func (Book) Create

func (b Book) Create(rw http.ResponseWriter, req *http.Request)

func (Book) Download

func (b Book) Download(rw http.ResponseWriter, req *http.Request)

func (Book) Find

func (b Book) Find(rw http.ResponseWriter, req *http.Request)

func (Book) FindMany

func (b Book) FindMany(rw http.ResponseWriter, req *http.Request)

FindMany handles bulk fetching books by given OData query. If $top number not specified maxOnPage will be used. In case number of requested books is more than maxOnPage then nextLink will be rendered in response.

func (Book) Route

func (b Book) Route(rtr chi.Router)

type BookLogic

type BookLogic interface {
	Import(context.Context, models.Book) error
	Fetch(context.Context, models.Book) (models.Book, error)
	FetchMany(context.Context, models.DataFilter) ([]models.Book, error)
	ExportToCSV(context.Context, models.DataFilter) ([]byte, error)
	AddToFavorites(context.Context, models.Reader, models.Book) error
	AddToWishlist(context.Context, models.Reader, models.Book) error
}

type Reader

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

func NewReader

func NewReader(logic ReaderLogic, logger models.Logger) Reader

func (Reader) Login

func (r Reader) Login(rw http.ResponseWriter, req *http.Request)

Login handles authorization process of created models.Reader.

func (Reader) Logout

func (r Reader) Logout(rw http.ResponseWriter, req *http.Request)

Logout handles logout process.

func (Reader) Refresh

func (r Reader) Refresh(rw http.ResponseWriter, req *http.Request)

Refresh handles process of token pair refreshment.

func (Reader) Register

func (r Reader) Register(rw http.ResponseWriter, req *http.Request)

Register creates new models.Reader.

func (Reader) Route

func (r Reader) Route(rtr chi.Router)

type Router

type Router struct{ chi.Router }

func NewRouter

func NewRouter(routes ...func(chi.Router)) Router

type Server

type Server struct{ *http.Server }

func NewServer

func NewServer(hdl http.Handler) (*Server, error)

func (*Server) Run

func (srv *Server) Run() error

type Token

type Token interface {
	models.AccessToken | models.RefreshToken
}

Jump to

Keyboard shortcuts

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