The tools and features that are in this project are as follows
- Go
- Swagger
- gin-gonic/gin
- JWT authentication
- Rate limitation
- CSRF protection
- CORS
- MySQL
- Prometheus
- Grafana
A basic implementation of Tasks list. You can create your own user (or choose one that is already created when you setup the project) and create tasks that are only yours. You can view all the tasks that are in the project assuming that all the users registered are in the same organization.
- You need to have Go installed on your system. You can check the website for Go to download according to your OS.
- Then you need to install Prometheus and Grafana. You can skip this part if you are not interested in metrics.
- MySQL is used as the database for this project. Download and install it for your system accordingly.
- golang-migrate is used for migration so install that as well
- also, create 2 databases in your system with the names:
tasks_list_go
andtest_tasks_list_go
- You can follow the instructions on their website and download it.
- The only changes you need to make is that for Prometheus, you need to change the targets key to
localhost:8080
fromlocalhost:9090
so that it targets our application - Prometheus
- Grafana
- Then you need to configure golang-migrate. Instructions to download are on their website.
- golang-migrate
-
Setup the DB first
- Navigate to /db/migrations folder
- use the following line to create your dev and test DB
migrate -database "mysql://[dbUser]:[dbPassword]@tcp([dbHost]:[dbPort])/[dbName]" -path . up
- Doing so would make 2 DB's for you. tasks_list_go (dev DB) and test_tasks_list_go (test DB)
- You would have a dummy email already their for you along with some tasks created already
- email and password: [email protected]
-
Run the code with command:
go run main.go
in root folder -
Swagger instructions
- You would need your JWT token and CSRF token to login the app and use its features
- to get your CSRF token, route to:
GET /protected
and copy the code - now, you can either Register or Login yourself
- logging in would give you the JWT that is valid for 1 hour
- copy your JWT token and click on either the lock icon on any of the routes or the Authorize button on the top right corner
- be sure to add the JWT in this format
Bearer [your JWT token]
for Swagger - P.S. unlike Swagger, if you are using Postman, you need to go to Authorization tab and add your Bearer token only and not the
Bearer
string
-
Prometheus instructions
- Assuming you did everything that is stated above, navigate to:
localhost:9090
to view the Prometheus page - P.S. for windows, we run the .exe file for Prometheus wherever you downloaded the zip file and extracted it
- in the main screen, you can choose any of following key to view your metrics
- details for the keys are as follows
get_all_tasks_list_request_count
: No. of time GET /api/v1/tasks was calledget_all_user_tasks_list_request_count
: No. of time GET /api/v1/userTasks was calledget_task_request_count
: No. of time GET /api/v1/task/:id was calledcreate_task_request_count
: No. of time POST /api/v1/tasks was callededit_task_request_count
: No. of time PATCH /api/v1/editTask was callededit_task_status_request_count
: No. of time PATCH /api/v1/editTaskStatus was calleddelete_task_request_count
: No. of time DELETE /api/v1/deleteTask/:id was calledregister_user_request_count
: No. of time POST /api/v1/register was calledget_user_request_count
: No. of time POST /api/v1/user was calledlogin_request_count
: No. of time POST /api/v1/login was callededit_user_request_count
: No. of time PATCH /api/v1/editUser was called
- Assuming you did everything that is stated above, navigate to:
-
Grafana instructions
- Assuming you did everything that is stated above, navigate to:
localhost:3000
to view the Grafana page - P.S. for windows, we run the .exe file for Grafana wherever you downloaded the zip file and extracted it
- on the main screen you can see
Add your first data source
, click it and selectPrometheus
- give it a name
- set the
Prometheus server URL
tohttp://localhost:9090
- navigate to the bottom and select
Save and Test
- once complete, navigate to the homepage
- on the left you can see
Dashboards
, click it and then clickNew Dashboard
- select your datasource for that you created
- here you can see visualisation of your data
- add any of the metric that are listed above, set the label to
instance
and value to `localhost:9090 - P.S. you MIGHT need to refresh Prometheus and Grafana once or twice for the changes to reflect
- Assuming you did everything that is stated above, navigate to:
000x1
: Error querying all tasks000x2
: Error scanning rows for all tasks000x3
: Error querying all user tasks000x4
: Error scanning rows for all user tasks000x5
: No record found when fetching a single task000x6
: Error when creating a task000x7
: Error editing a task000x8
: Error editing a task status000x9
: Error deleting a task000x10, 000x11 and 000x12
: Error parsing request body for Create task, Edit task and Edit Task status000x20
: No record found when fetching User000x21
: Error hashing user password when Registering and Editing User000x22
: Error inserting User into DB when Registering000x23
: Error editing user000x24
: Invalid request params for fetching user000x25
: Invalid request params during login000x26
: Invalid credentials during login000x27
: Invalid request params when editing user000x28 and 000x29
: Invalid email format when creating and editing a user000x30, 000x31 and 000x32
: Invalid email format when fetching User, login and editing user000x33
: Email already taken when editing user000x74
: Authorinzation header not present000x75
: Invalid JWT000x76
: Expired JWT