Documentation ¶
Index ¶
- Variables
- type Handler
- func (h *Handler) CreateProduct(w http.ResponseWriter, r *http.Request)
- func (h *Handler) DeleteProduct(w http.ResponseWriter, r *http.Request)
- func (h *Handler) GetProduct(w http.ResponseWriter, r *http.Request)
- func (h *Handler) ListProducts() http.HandlerFunc
- func (h *Handler) UpdateProduct(w http.ResponseWriter, r *http.Request)
- type Price
- type Product
- type ProductFilter
- type ProductUpdate
- type Service
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("shop: not found") ErrConflict = errors.New("shop: conflict on id") )
Functions ¶
This section is empty.
Types ¶
type Handler ¶
Handler implements http.Handler and provides an interface for API requests to interact with the ProductService.
func NewHandler ¶
NewHandler returns a new Handler.
func (*Handler) CreateProduct ¶
func (h *Handler) CreateProduct(w http.ResponseWriter, r *http.Request)
POST /products
func (*Handler) DeleteProduct ¶
func (h *Handler) DeleteProduct(w http.ResponseWriter, r *http.Request)
Delete a product identified in the URL. DELETE /products/{productID}
func (*Handler) GetProduct ¶
func (h *Handler) GetProduct(w http.ResponseWriter, r *http.Request)
GetProduct will parse and respond to an API request for a specific product defined by its {productID} in the request URL. GET /products/{productID}
func (*Handler) ListProducts ¶
func (h *Handler) ListProducts() http.HandlerFunc
ListProducts returns a subset of products defined by the filters in the URL. GET /products
func (*Handler) UpdateProduct ¶
func (h *Handler) UpdateProduct(w http.ResponseWriter, r *http.Request)
Update a subset of a products attributes. The product is identified by its {productID} in the URL. PATCH /products/{productID}
type Product ¶
type Product struct { ID string `json:"id,omitempty"` Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` Price Price `json:"price,omitempty"` }
Product defines a single product, represented by its unique ID.
type ProductFilter ¶
type ProductFilter struct{}
ProductFilter defines the attributes a user can use to filter/limit a subset of results in a request for a list of products.
type ProductUpdate ¶
type ProductUpdate struct{}
ProductUpdate defines the attributes that can be updated in a PATCH request.
type Service ¶
type Service interface { CreateProduct(ctx context.Context, p Product) (Product, error) GetProduct(ctx context.Context, id string) (Product, error) ListProducts(ctx context.Context, f ProductFilter) ([]Product, error) UpdateProduct(ctx context.Context, id string, upd ProductUpdate) (Product, error) DeleteProduct(ctx context.Context, id string) error }
Service