-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (55 loc) · 1.72 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
controller "github.com/AIRONAX-Developer/go-gin-rest-api/src/controller"
service "github.com/AIRONAX-Developer/go-gin-rest-api/src/service"
"math"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
var loginService service.LoginService = service.StaticLoginService()
var jwtService service.JWTService = service.JWTAuthService()
var loginController controller.LoginController = controller.LoginHandler(loginService, jwtService)
server := gin.New()
fmt.Println("loginService ==>> ", loginService)
fmt.Println("jwtService ==>> ", jwtService)
fmt.Println("loginController ==>> ", loginController)
server.POST("/login", func(ctx *gin.Context) {
token := loginController.Login(ctx)
fmt.Println("token ==>> ", token)
if token != "" {
ctx.JSON(http.StatusOK, gin.H{
"token": token,
})
} else {
ctx.JSON(http.StatusUnauthorized, nil)
}
})
server.POST("/emi", func(ctx *gin.Context) {
// EMI Calculation Formula
/*
E is EMI
P is Principal Loan Amount
r is rate of interest calculated on monthly basis. (i.e., r = Rate of Annual interest/12/100. If rate of interest is 10.5% per annum, then r = 10.5/12/100=0.00875)
n is loan term / tenure / duration in number of months
E = P*r* (1+r)^n/(((1+r)^n)-1)
*/
P := 1000000
r := 10.5 / 12 / 100
n := 120
numerator := math.Pow((1 + r), float64(n))
denominator := (math.Pow((1+r), float64(n)) - 1)
Emi := int(math.Round(float64(P) * r * numerator / denominator))
ctx.JSON(http.StatusOK, gin.H{
"Principal": P,
"InterestRate": r,
"Tenure": n,
"Emi": Emi,
"TotalEmi": (Emi * n),
"TotalInterest": ((Emi * n) - P),
})
})
port := "8080"
server.Run(":" + port)
}