A backend API for an e-commerce platform built with Go. This project provides essential features for running an online store, including user authentication, product management, and order processing.
- User Authentication: Secure user registration and login using JSON Web Tokens (JWT).
- Admin Seeding: Automatic creation of an admin user on startup from environment variables.
- RESTful API: A clean and organized API structure.
- Configuration-driven: Easy setup using environment variables.
- Email Integration: Ready for integrating with an email service for notifications.
- Go
- PostgreSQL
- JWT for Authentication
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
- Go (version 1.18 or higher)
- PostgreSQL
- Git
-
Clone the repository:
git clone https://github.com/Asura409/Ecommerce-api.git cd Ecommerce-api -
Set up environment variables: Create a
.envfile in the root of the project by copying the example file.cp .env.example .env
Now, open the
.envfile and fill in your specific configuration details, such as your database credentials and a strong JWT secret. -
Install dependencies: This command will download the necessary Go modules.
go mod tidy
-
Set up the database: Ensure your PostgreSQL server is running. Connect to it and create the database you specified in the
DATABASE_DSNvariable in your.envfile. -
Run the application:
go run main.go
The API server should now be running on the port specified in your
.envfile (default is3001).
The application is configured using environment variables stored in a .env file.
| Variable | Description | Example |
|---|---|---|
APP_PORT |
The port on which the application server will listen. | 3001 |
DATABASE_DSN |
The Data Source Name for connecting to the PostgreSQL database. | "host=localhost user=blog password=asura dbname=bp port=5432" |
JWT_SECRET |
A secret key used to sign and verify JWTs. | "your-super-secret-key" |
ADMIN_EMAIL |
The email for the default admin user, created on startup. | "[email protected]" |
ADMIN_PASSWORD |
The password for the default admin user. | "admin123" |
EMAIL_API_KEY |
The API key for your chosen email service provider. | "your-email-api-key" |
EMAIL_SENDER |
The email address from which transactional emails will be sent. | "[email protected]" |
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request