This project is a Go-based CRUD API for inventory management of products. It utilizes MySQL for persistent data storage and provides API endpoints for managing your inventory through:
- GET: Retrieve information about existing products.
- POST: Create new products and add them to your inventory.
- PUT: Update existing product details in your inventory.
- DELETE: Remove unwanted products from your inventory.
This API empowers you to manage your product stock efficiently, facilitating tasks like:
- Tracking product quantities and prices.
- Adding new products to your inventory.
- Updating existing product details like descriptions or variations.
- Removing or archiving products no longer available.
This is a simple yet powerful tool for developers and individuals wanting to build applications with inventory management capabilities.
-
Install and Run MySQL:
- Follow the instructions for your operating system to install and start the MySQL server.
-
Choose MySQL User:
-
Use Root User: If you prefer to use the root user, you can skip steps 2.1 and 2.2. However, using a dedicated user with limited privileges is generally recommended for security reasons.
-
Create a New User: To create a separate user with appropriate permissions, proceed with the following steps:
- Access the MySQL console:
mysql -u root -p
- Create a user (replace
username
andpassword
with your desired credentials):CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
- Grant necessary permissions to the user:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost'; # Grant all privileges for simplicity, but consider granting only specific privileges for better security
- Access the MySQL console:
-
-
Create Database and Table:
- Create the database:
CREATE DATABASE Inventory;
- Switch to the database:
USE Inventory;
- Create the table:
CREATE TABLE products ( id int NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, quantity int, price float(10,7), PRIMARY KEY(id) );
- Create the database:
-
Store Password :
- Store the MySQL password securely in your environment:
echo "export DB_PASSWORD=Your_Password" >> ~/.zshrc # For Z shell export DB_PASSWORD=Your_Password # For current session
- Store the MySQL password securely in your environment:
- Build the Project:
go build
- Run the executable:
./file_name