ecommerce api-rest with basic CRUD operations (Create, Read, Update and Delete) products, suppliers, etc. Manage automatically invoice and shipping operations
- Clone the repo
git clone https://github.com/AlexVonEinzbern/go-rest-api.git
- Add an
.env
file in the main root of the project containing the environment variables with the database credentials. E.g. :
DB_HOST=host.docker.internal
DB_USER=voneinzbern
DB_PASSWORD=bacbabaBDBWUOB3242obf
DB_NAME=go-rest-api
- Uncomment the followig lines on
db/connection.go
(Line 8):
//"github.com/joho/godotenv"
(Lines 15-19)
//err := godotenv.Load(".env")
//if err != nil {
// log.Fatal("Error loading .env file")
//}
- Uncomment the following line on
Dockerfile
(Line 27):
#COPY .env /
- Build the project using
Docker
:
docker build -t go-rest-api .
- Run the container:
On Mac
:
docker run -it -p 8080:8080 --env-file=".env" go-rest-api
On Linux
it is necessary to use the flag --add-host=host.docker.internal:host-gateway
docker run --add-host=host.docker.internal:host-gateway -it -p 8080:8080 --env-file=".env" go-rest-api
https://go-rest-api.onrender.com/api/v1
After the project is running, an interactive documentation created using Swagger
can be visited on http://localhost:8080/swagger/index.html#/
Note: The online documentation can be found here.
Some examples: