The project go-shopping
is a playground to practice writing an HTTP service in GoLang
using gin
and gorm
.
The project represents a back-end microservice that serves HTTP calls to do basic CRUD (create/read/update/delete) operations on the items in a small magic shop :)
The project was inspired by this article about Gin&Gorm and this article about application layers. The implementation follows official documentation and this article.
Following this article, the application is separated into 3 layers:
- repositories: interact directly with the database;
- services: contain the business logic;
- handlers: accept requests and builds the responses.
Run all tests in the project, but remove the db file first (workaround):
rm -f routers/items.db
go test ./...
If all tests pass, start the HTTP service with:
go run main.go
and the service will run on localhost:8080
.
Additionally, in the root of the repository there are following files:
Go-Shopping.postman_collection.json
- a Postman collection that can be used for reference to send HTTP calls;items.db
- a small SQLite Database to start using the project without the need to care about any pre-requisites;items.sql
- a backup file containing SQL queries to create an SQLite Database if it does not exist.