interest-calculator-svc is production grade service to calculate simple interest and store it on mongo DB
This service provides different feature like api extendability, reuseability, sepreration of concern
- App layer mainly contains very specfic code to a different apis (i.e. in our case interest-cal-api) and which takes externl input. e.g
- Business layer coantains packages which used by the app layer to process the request related store and retrive data. It also some reusable components.
- There should be no circular imorts and imports are only done from down to top (i.e. any code in app packages could import any package in business layer.) But vicea-verse should not be done.
- This service could be build with different version. Need to sepecify in Makefile. Default value of VERSION is 1.0
- GoFiber - for hosting service api handles
- Mongodb - for storing data
- Docker - for containerization
- counterfeiter- for generating mocks
- testify - for test assertion
- Install docker and docker compose
- install golang
To run service run this command in interest-calculator-svc.This first test the service and build the docker image will specified version and once done will spawn two containers (i.e.mongodb-container, interest-cal)
make start
To stop service run this command in interest-calculator-svc.This will stop and removed the running containers
make stop
To test service seperatly run this command. This will run all the table driven unit tests for service withour caching the last output and also checks the race condition.
make test
To re-generate the mocks run this command.
make gen
To test the apis run make start
and import the postmen collection in postamn or use curl
to hit apis. All the api will hosted on localhost:3500
HTTP Verbs | Endpoints | Action |
---|---|---|
POST | /api/v1/si | To create simpleinterest record in mongodb |
GET | /api/v1/si/{id} | To get simpleinterest record from mongodb |
DELETE | /api/v1/si/{id} | To delete simpleinterest record from mongodb |
.
├── app
│ └── services
│ └── interest-cal-api
│ ├── handlers
│ │ ├── handler.go
│ │ └── v1
│ │ └── sigrp
│ │ └── sigrp.go
│ ├── main.go
│ └── start
│ └── start.go
├── bin
│ └── interest-cal-api
├── business
│ ├── core
│ │ ├── entities
│ │ │ └── simpleinterest.go
│ │ └── simpleInterest
│ │ ├── fakerepo
│ │ │ ├── fakeMongo
│ │ │ │ └── fake_repository.go
│ │ │ └── genfake.go
│ │ ├── repo
│ │ │ └── repo.go
│ │ ├── svc.go
│ │ └── svc_test.go
│ └── data
│ └── repoConn.go
├── docker
│ ├── docker-compose.yml
│ └── dockerfile
├── go.mod
├── go.sum
├── Makefile
└── README.md