This GitHub repo has my attempt to build simple REST APIs for practicing go.
The project contains simple APIs for adding, editting, retrieving and deleting books.
This is used for educational and practicing purpose to learn design principals, Go lang and other DevOps toolchain like Docker.
The code base follows Hexagonal Architecture and Domain-Driven Design principals, where the code is broken down to:
-
Domain
- Model
- Service
-
Ports
-
Adapters
-
Get all books:
-
URL :
/book
-
Method :
GET
-
-
Add book:
-
URL :
/book
-
Method :
POST
-
Data constraints :
{ "name": 'test',author" : 'test', "publication": 'test' }
-
-
Get book:
-
URL :
/book/[id]
-
Method :
GET
-
-
Update book:
-
URL :
/book/[id]
-
Method :
PUT
-
Data constraints :
{ "name": 'test',author" : 'test', "publication": 'test' }
-
-
Delete book:
-
URL :
/book/[id]
-
Method :
DELETE
-
-
Install Go and Mysql
-
Clone the repo on your machine
-
Update the database USERNAME, PASS and DATABASE constants in main.go file
-
Run
- From root of the repo on your terminal run the following command
go run main.go
- (Optional) Use docker compose
- Update the docker-compose.yml MYSQL_ROOT_PASSWORD and MYSQL_DATABASE fields
docker compose build docker compose up
- Unit tests
- Config files
- Authentication