-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (48 loc) · 1.56 KB
/
main.go
File metadata and controls
57 lines (48 loc) · 1.56 KB
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
package main
import (
"account-mgmt/src/db"
"account-mgmt/src/routes"
"account-mgmt/src/routes/account"
"account-mgmt/src/routes/txn"
"account-mgmt/src/routes/user"
"fmt"
"github.com/gin-gonic/gin"
"log"
)
func main() {
database := db.Connect()
if err := database.AutoMigrate(); err != nil {
log.Panicln(err)
return
}
fmt.Println("Hello Sanjay, Welcome to Account-Management tool.")
r := gin.Default()
r.GET("/", routes.HomePage)
r.POST("/", routes.HomePage)
accEndpoint := account.AccEndpoint(database, "account")
r.GET("/accounts", accEndpoint.GetAccounts)
r.GET("/account/:id", accEndpoint.GetAccountById)
r.POST("/account", accEndpoint.NewAccount)
r.PUT("/account", accEndpoint.UpdateAccount)
r.DELETE("/account", accEndpoint.DeleteAccount)
usrEndpoint := user.UsrEndpoint(database, "user")
r.GET("/users", usrEndpoint.GetUsers)
r.GET("/user/:id", usrEndpoint.GetUserById)
r.POST("/user", usrEndpoint.NewUser)
r.PUT("/user", usrEndpoint.UpdateUser)
r.DELETE("/user", usrEndpoint.DeleteUser)
txEndpoint := txn.TxEndpoint(database, "txn")
r.GET("/txn/:id", txEndpoint.GetTxnById)
r.POST("/txn", txEndpoint.NewTxn)
r.POST("/txns", txEndpoint.GetTxns)
r.PUT("/txn", txEndpoint.UpdateTxn)
r.DELETE("/txn", txEndpoint.DeleteTxn)
// r.OPTIONS("/", OptionsHomePage)
//r.GET("/query", account.QueryString) // /query?name=sanjay&age=28
//r.GET("/path/:name/:age", account.PathParameters) // /path/sanjay/28
err := r.RunTLS(":8080", "cert/MwServerCA.crt", "cert/MwServerCA.key")
if err != nil {
log.Println("Certificate error.")
return
}
}