Documentation ¶
Index ¶
- Variables
- func DecodeDeleteBookRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodeGetBookRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodePostBookRequest(_ context.Context, r *http.Request) (interface{}, error)
- func DecodePutBookRequest(_ context.Context, r *http.Request) (interface{}, error)
- func EncodeBookResponse(_ context.Context, w http.ResponseWriter, response interface{}) error
- func EncodeErrorResponse(_ context.Context, err error, w http.ResponseWriter)
- func MakeDeleteBookENdpoint(svc BooksService) endpoint.Endpoint
- func MakeGetBookENdpoint(svc BooksService) endpoint.Endpoint
- func MakeHandler(svc BooksService, logger log.Logger) http.Handler
- func MakePostBookEndpoint(svc BooksService) endpoint.Endpoint
- func MakePutBookEndpoint(svc BooksService) endpoint.Endpoint
- type Book
- type BookServiceInstance
- func (svc BookServiceInstance) DeleteBook(ctx context.Context, id int) error
- func (svc BookServiceInstance) GetBook(ctx context.Context, id int) (Book, error)
- func (svc BookServiceInstance) PostBook(ctx context.Context, b Book) (int, error)
- func (svc BookServiceInstance) PutBook(ctx context.Context, id int, b Book) error
- type BooksService
- type DeleteBookRequest
- type ErrorResponse
- type GetBookRequest
- type GetBookResponse
- type PostBookRequest
- type PostBookResponse
- type PutBookRequest
Constants ¶
This section is empty.
Variables ¶
View Source
var (
InvalidBook = errors.New("Invalid Book")
)
Functions ¶
func DecodeDeleteBookRequest ¶
func DecodeGetBookRequest ¶
func DecodePostBookRequest ¶
func DecodePutBookRequest ¶
func EncodeBookResponse ¶
func EncodeBookResponse(_ context.Context, w http.ResponseWriter, response interface{}) error
func EncodeErrorResponse ¶
func EncodeErrorResponse(_ context.Context, err error, w http.ResponseWriter)
func MakeDeleteBookENdpoint ¶
func MakeDeleteBookENdpoint(svc BooksService) endpoint.Endpoint
func MakeGetBookENdpoint ¶
func MakeGetBookENdpoint(svc BooksService) endpoint.Endpoint
func MakeHandler ¶
func MakeHandler(svc BooksService, logger log.Logger) http.Handler
func MakePostBookEndpoint ¶
func MakePostBookEndpoint(svc BooksService) endpoint.Endpoint
func MakePutBookEndpoint ¶
func MakePutBookEndpoint(svc BooksService) endpoint.Endpoint
Types ¶
type Book ¶
type Book struct { ID int `json:"id"` Title string `json:"title"` Author string `json:"author"` AverageRating float32 `json:"average_rating"` ISBN string `json:"isbn"` ISBN13 string `json:"isbn13"` LanguageCode string `json:"language_code"` NumPages int `json:"num_pages"` RatingsCount int `json:"ratings_count"` TextReviewsCount int `json:"text_reviews_count"` PublicationDate time.Time `json:"publication_date"` Publisher string `json:"publisher"` }
Book represents a single book record
type BookServiceInstance ¶
BookServiceInstance implements the BookService interface
func (BookServiceInstance) DeleteBook ¶
func (svc BookServiceInstance) DeleteBook(ctx context.Context, id int) error
DeleteBook
type BooksService ¶
type BooksService interface { PostBook(ctx context.Context, b Book) (int, error) GetBook(ctx context.Context, id int) (Book, error) PutBook(ctx context.Context, id int, b Book) error DeleteBook(ctx context.Context, id int) error }
BookService is a CRUD interface for books
type DeleteBookRequest ¶
type DeleteBookRequest struct {
ID int `json:"id"`
}
DeleteBookRequest is the rpc request to delete a book record
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse is sent when the endpoint could not complete the request
type GetBookRequest ¶
type GetBookRequest struct {
ID int `json:"id"`
}
GetBookRequest is the rpc request message to get a book by id
type GetBookResponse ¶
type GetBookResponse struct {
Book Book `json:"book"`
}
GetBookResponse is the rpc response of the get request
type PostBookRequest ¶
type PostBookRequest struct {
Book Book `json:"book"`
}
PostBookRequest is RPC request message to post a new book
type PostBookResponse ¶
type PostBookResponse struct {
ID int `json:"id"`
}
PostBookResponse is a RPC response message to the post request
type PutBookRequest ¶
PutBookRequest is the rpc request to update an existing book
Click to show internal directories.
Click to hide internal directories.