-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (49 loc) · 1.49 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
// main.go
package main
import (
"github.com/lokesh20018/iitk-coin/controllers"
"log"
"github.com/lokesh20018/iitk-coin/models"
"github.com/lokesh20018/iitk-coin/middlewares"
"github.com/lokesh20018/iitk-coin/database"
"github.com/gin-gonic/gin"
)
func setupRouter() *gin.Engine {
route := gin.Default()
route.GET("/check", func(context *gin.Context) {
context.String(200, "good to go")
})
route.POST("/login", controllers.Login)
route.POST("/signup", controllers.Signup)
route.POST("/init", middlewares.Authz_Admin(), controllers.Account_init)
route.GET("/balance", middlewares.Authz(), controllers.GetBalance)
route.POST("/transfer", middlewares.Authz(), controllers.Transfer)
route.GET("/secretpage", middlewares.Authz(), controllers.Profile)
// api_file := route.Group("/secretpage")
// {
// protected_route := api_file.Group("/").Use(middlewares.Authz())
// {
// protected_route.GET("/", controllers.Profile)
// }
// }
return route
}
func main() {
err := database.InitDatabase()
if err != nil {
log.Fatalln("could not create database", err)
}
database.GlobalDB.AutoMigrate(&models.User{})
err2 := database.InitDatabaseAcc()
if err2 != nil {
log.Fatalln("could not create Acc ", err2)
}
database.GlobalDBAcc.AutoMigrate(&models.Account{})
err3 := database.InitDatabaseTrans()
if err3 != nil {
log.Fatalln("could not create Transfer database.... ", err3)
}
database.GlobalDBTrans.AutoMigrate(&models.Transaction{})
route := setupRouter()
route.Run(":8080")
}