api

package
v0.0.0-...-4a724ca Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPServer

func NewHTTPServer(ctx context.Context, endpoints Endpoints) http.Handler

NewHTTPServer creates new server to serve endpoints

Types

type CreateBookRequest

type CreateBookRequest struct {
	Isbn   string        `json:"isbn"`
	Title  string        `json:"title"`
	Author models.Author `json:"author"`
}

CreateBookRequest Isbn, Title, Author struct

type Endpoints

type Endpoints struct {
	GetBooks   endpoint.Endpoint
	CreateBook endpoint.Endpoint
	GetBook    endpoint.Endpoint
	UpdateBook endpoint.Endpoint
	DeleteBook endpoint.Endpoint
}

Endpoints holds endpoints

func MakeEndpoints

func MakeEndpoints(s Service) Endpoints

MakeEndpoints makes endpoints to handle requests

type GetBookResponse

type GetBookResponse struct {
	ID     int           `json:"id"`
	Isbn   string        `json:"isbn"`
	Title  string        `json:"title"`
	Author models.Author `json:"author"`
}

GetBookResponse returns single book

type GetBooksRequest

type GetBooksRequest struct{}

GetBooksRequest struct

type GetBooksResponse

type GetBooksResponse struct {
	Books []models.Book `json:"books"`
}

GetBooksResponse struct of slice of Books

type IDRequest

type IDRequest struct {
	ID string
}

IDRequest gets single book

type OkResponse

type OkResponse struct {
	Ok string `json:"ok"`
}

OkResponse struct

type Service

type Service interface {
	GetAllBooks(ctx context.Context) ([]models.Book, error)
	CreateNewBook(ctx context.Context, isbn, title string, author models.Author) (string, error)
	GetBook(ctx context.Context, id string) (*models.Book, error)
	UpdateBook(ctx context.Context, id, Isbn, Title string) (string, error)
	DeleteBook(ctx context.Context, id string) (string, error)
}

Service is a main microservice interface

func NewService

func NewService(rep models.Repository, logger log.Logger) Service

NewService returns new instance of servise

type UpdateBookRequest

type UpdateBookRequest struct {
	ID    string `json:"id"`
	Isbn  string `json:"isbn"`
	Title string `json:"title"`
}

UpdateBookRequest updates book

Jump to

Keyboard shortcuts

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