Documentation
¶
Overview ¶
Package handlers contains our route handlers. It uses the models package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateProduct ¶
func CreateProduct(db *sql.DB) httprouter.Handle
CreateProduct assumes that the request body is a JSON object containing the details of the product to be created. It extracts that object into a product and uses the createProduct method to create a product with these details.
func DeleteProduct ¶
func DeleteProduct(db *sql.DB) httprouter.Handle
DeleteProduct extracts the id from the requested URL and uses it to delete the corresponding product from the database.
func GetConfig ¶
func GetConfig(s []byte) httprouter.Handle
GetConfig extracts the id from the requested URL and uses it to delete the corresponding product from the database.
func GetProduct ¶
func GetProduct(db *sql.DB) httprouter.Handle
GetProduct retrieves the id of the product to be fetched from the requested URL, and uses the getProduct method, created in the previous section, to fetch the details of that product.
If the product is not found, the handler responds with a status code of 404, indicating that the requested resource could not be found. If the product is found, the handler responds with the product.
func GetProducts ¶
func GetProducts(db *sql.DB) httprouter.Handle
GetProducts uses the count and start parameters from the querystring to fetch count number of products, starting at position start in the database. By default, start is set to 0 and count is set to 10. If these parameters aren't provided, this handler will respond with the first 10 products.
func UpdateProduct ¶
func UpdateProduct(db *sql.DB) httprouter.Handle
UpdateProduct extracts the product details from the request body. It also extracts the id from the URL and uses the id and the body to update the product in the database.
Types ¶
This section is empty.