balatamoghna / Go-CryptoAPIDockerized

A dockerized version of the already existing CryptoAPI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go-CryptoAPIDockerized

Dockerized project of the CryptoCurrency API

Libraries used:

  • GORM - The fantastic ORM library for Golang
  • Fiber - Express inspired web framework written in Go
  • RabbitMQ - RabbitMQ is a message broker for cohesiveness between main and worker(to send emails).

Installation

Run the following go gets to install the necessary libraries.

go get gorm.io/gorm
go get github.com/gofiber/fiber/v2
go get github.com/gofiber/jwt/v3
go get gorm.io/driver/mysql
go get github.com/streadway/amqp
go get github.com/golang-jwt/jwt/v4

Along with these libraries, Install RabbitMQ as well as MySQL

Once everything is setup, 1.Create a MySQL database named "kryptodb" 2.Startup RabbitMQ Everything is set and finished.

Run the project(Updated)

Simply run docker-compose up

Documentation

The project has three subfolders namely backend,model and worker

  • The backend consists of the email sender, object model relationship (along with driver to local MySQL database) and a route handler for ease of scalability.
  • The model contains the currency details and user alerts models used to represent the structure of the information. Also kept seperately to aid in ease of readablitly and scalability.

API Endpoint functions(only handlers):

  • Login - Function to get JWT Token from given parameters
  • AlertCreate - Function to create alert from user given parameters (email,target,currency aka symbol of the cryptocurrency from given API.example: btc,eth,etc)
  • AlertDelete - Function to delete alert by given ID
  • FetchAlerts - Function to fetch all alerts from user
  • FetchTriggeredAlerts - Function to fetch only triggered alerts from user

Constants used:

  • DNS is a constant. const DNS = "root:pass@tcp(127.0.0.1:3306)/kryptodb?charset=utf8mb4&parseTime=True&loc=Local"
  • JWT Token is a constant since nothing about user registration was specified. eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6dHJ1ZSwiZW1haWwiOiJiLmJhbGF0YW1vZ2huYUBnbWFpbC5jb20iLCJleHAiOjE2MzE1NDM4ODZ9.Ahh7X-Z2y_gg80EGinmp7hbzsirHc7N_RNTkY-0ZGFw
  • Attain the JWT Token through login by using these parameters: user=b.balatamoghna@gmail.com&pass=Krypto
  • Although it is best practice to not have credentials inside a git repo, the smtp email and password for a throwaway email has been included.(for obvious reasons, I won't be writing the creds here)

Currency details Model

	ID           int     `gorm:"auto_increment" json:"id"`
	Symbol       string  `gorm:"primaryKey" json:"symbol"`
	Name         string  `json:"name"`
	CurrentPrice float64 `json:"current_price"`
	Updated      int64   `gorm:"autoUpdateTime:milli"

User alerts Model

	ID        int     `gorm:"primaryKey;auto_increment" json:"id"`
   Email     string  `json:"email"`
   Currency  string  `json:"currency"`
   Target    float64 `json:"target"`
   Triggered string  `json:"triggered"`
   CreatedAt time.Time
   DeletedAt gorm.DeletedAt `gorm:"index"`

Screenshots

go run main.go go run main.go go run worker.go go run worker.go get JWT Token get JWT Token create alert create alert fetch ALL alerts fetch ALL alerts fetch triggered alerts fetch triggered alerts delete alert delete alert alert triggered alert triggered sending mail from worker sending mail from worker mail recieved mail recieved fetchall shows alert has been triggered fetchall shows alert has been triggered RabbitMQ queue RabbitMQ queue

Note

The worker.go utilizes a function in the backend folder in email.go file. Although it is in the same folder as the backend for the main.go file, there are not shared functions between the main.go and worker.go where the only connection between them is the Rabbit MQ message broker thus ensuring independency. The backend can be a little cleaner, and worker can be in a seperate folder outside the main project in order to follow nomenclature and best practices.

Email: b.balatamoghna@gmail.com VIT Email: b.balatamoghna2018@vitstudent.ac.in

Problem statement

Incase the problem statement is required. Here is the link.

About

A dockerized version of the already existing CryptoAPI


Languages

Language:Go 87.4%Language:Dockerfile 8.1%Language:Shell 4.5%