A simple RESTful API using gin-gonic for the web framework and gorm for the database ORM. This project is using Repository Pattern to separate the database and the business logic.
The project includes the following features:
- RESTful API endpoint
- Standard CRUD operations
- Data validation
- GEO IP lookup
- JWT-based authentication
- Database migration
- Postman documentation and API testing
Note:
- The geoip info service is provided by freegeoip.live that may not be available when you try this project:(
Please follow the instructions to install Go on your local machine. This project requires Go 1.17 or higher+.
We also need to install Docker if you want to try the project without setting your own environment.
After all done, run the following commands to start the project:
# Clone this repo
git clone https://github.com/mr687/simple-go-rest-api.git
# Go to the project directory
cd simple-go-rest-api
# Install dependencies
go mod init
# Duplicate the .env.example file to .env and fill in your own values
cp .env.example .env
# Run postgreSQL database via Docker compose
docker compose up -d
# docker-compose up -d
# Start the rest server
go run main.go
# Server running default on http://localhost:8080
The API documentation is hosted on Postman Doc.