-
The API hasn't deployed on a VPS as requested (only locally using minikube, yaml files for the API and the database are attached). To compensate for this, the author adds some additional features including:
- Clean Code Architecture;
- Unit Testing as shown here;
- Additional endpoint for getting user by id as shown here;
- The usage of JSON Web Token as shown here.
-
The screenshot for proof of local deployment is attached here inside the local-deployment-screenshots folder. View it according to the sorted order.
-
The Architecture Diagram can be accessed on Figjam. It is also attached inside the root folder as local-architecture-diagram.png.
-
The API Documentation is accessible here
-
Admin credential is the following
email: admin@gmail.com
password: deall123
- User credential is the following
email: user@gmail.com
password: deall123
This is a REST API mini-project created for Deall Application Proccess for Backend Engineer position. The project is created in Go Programming Language and uses MySQL as the RDBMS. The project is using Uncle Bob's Clean Architecture of Systems. See more here. Without further ado, lets jump right in into the contents.
As previously mentioned, the project is created using Go Programming Language and MySQL RDBMS. The Technologies/Libraries use in this project are followings:
Testing & Utilities:
- vektra/mockery for creating some mocks
- stretchr/testify for unit testing
- spf13/viper for environment configurations
Deployment:
- Docker
- Minikube for Local Kubernetes Cluster
The API Documentation can be accessed here.
Deploying the project locally is pretty straightforward. Follow the How To Deploy The Project Locally part and access with routes provided in the API Documentation.
It can be also ran without Docker or Kubernetes.
- Clone the repo.
- Provides the following environment variables. Make sure MySQL is installed and schema created. Type those values in to their respective variables.
DB_URL=localhost:3306
DB_USER=<<YOUR_MYSQL_USERNAME>>
DB_PASSWORD=<<YOUR_MYSQL_PASSWORD>>
DB_NAME=<<YOUR_CREATED_DB>>
Or use the following launch.json for running on debug mode on vscode:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"cwd": "${workspaceFolder}",
"env": {
"DB_URL": "localhost:3306",
"DB_USER": <<YOUR_MYSQL_USERNAME>>,
"DB_PASSWORD": <<YOUR_MYSQL_PASSWORD>>,
"DB_NAME": <<YOUR_CREATED_DB>>,
},
"args": []
}
]
}
- Run using debug mode on vscode or type:
go run main.go
- Then access the following url.
Run the following command to test the API.
The following command is applicable for Windows Powershell. Other OS might edit some of the command for it to run.
go test ./... -coverprofile="cover.out"
go test ./business/ -coverprofile="cover.out"
go tool cover -html="cover.out"
The project is (currently) can only be ran locally.
- Docker and minikube installed (Check here for docker installation and her for minikube installation)
- Kubectl installed (minikube usually has kubectl dependency so additional installation is not necessary)
- Starting minikube using docker
minikube start --driver=docker
- Applying yaml for mysql application deployment. Secrets, configmap, deployment and service are inside the same file.
kubectl apply -f https://raw.githubusercontent.com/daffaalex22/seleksi-deall/main/mysql.yaml
- Applying yaml for API application deployment
kubectl apply -f https://raw.githubusercontent.com/daffaalex22/seleksi-deall/main/api.yaml
- Check if the application is running
kubectl get all
Or
kubectl get pods
- Forward service to be LOCALLY accessible. With the following command, minikube will return a url for accessing the API. The API is can then be tested on postman.
minikube service api-service --url
- Stop minikube
minikube stop