Skip to content

Latest commit

 

History

History
182 lines (168 loc) · 4.04 KB

README.md

File metadata and controls

182 lines (168 loc) · 4.04 KB

go-rest-api

ecommerce api-rest with basic CRUD operations (Create, Read, Update and Delete) products, suppliers, etc. Manage automatically invoice and shipping operations

How to use this repo?

Do it by yourself

  • 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

Use the API

https://go-rest-api.onrender.com/api/v1

Documentation

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:

Fig 1. Documentation preview.

Fig 2. Example of GET request.

Fig 3. Example of POST request.

Fig 4. Example of PATH (UPDATE) request.

Fig 5. Example of GET request using date.

Fig 6. Example of DELETE request.

Fig 7. Example of model.