This is a server for managing virtual inventory.
- Prerequisites
- Getting Started
- Creating the Swagger Document
- Building the Project
- Running the Server
- Setting Up Cron Job
- Swagger Documentation
- Environment Variables
Ensure you have the following installed:
- Go (version 1.22 or higher)
- Git
- Cron
- Swag (for generating Swagger documentation)
Clone the repository:
git clone https://gitlab.com/valensas/intern-projects/vinventory/backend.git
cd vinventory
swag init -g cmd/server/main.go
go build -o vinventory cmd/server/main.go
This will create an executable file named vinventory in the project directory.
To start the server, run:
./vinventory
The server will start on localhost:8080.
To set up a cron job to run the 'NotifyExpiringWarranties' job, follow these steps:
- Install and Start cron (needed for Linux systems, in Mac it comes preinstalled):
sudo apt update
sudo apt install cron
sudo systemctl start cron
sudo systemctl enable cron
- Open the crontab editor:
crontab -e
- Add the following line to schedule the job to run every day at midnight:
0 0 * * * cd path/to/parent/directory/of/binary/file && ./vinventory notification_job
Swagger documentation is available at http://localhost:8080/swagger/index.html.
- DB_HOST
- DB_PORT=8080
- DB_USER
- DB_PASSWORD
- DB_NAME
- AZURE_CLIENT_ID
- AZURE_TENANT_ID
- AZURE_CLIENT_SECRET
- SMTP_HOST
- SMTP_PORT
- SMTP_USERNAME
- SMTP_PASSWORD
- SENDER_EMAIL
- RECEIVER_EMAIL
- export GITLAB_TOKEN
- export DOCKER_USERNAME
- export CC=gcc
- export CXX=g++
- export CGO_CFLAGS="-Wno-deprecated"