-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.go
76 lines (57 loc) · 1.59 KB
/
App.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
71
72
73
74
75
76
package main
import (
// models "attendance/Package/Models"
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/jinzhu/gorm"
)
type AppInterfaceImpl struct {
MuxRouter *mux.Router
dB *gorm.DB
}
func NewApp(MuxRouter *mux.Router, dB *gorm.DB) *AppInterfaceImpl {
app := &AppInterfaceImpl{
MuxRouter: MuxRouter,
dB: dB,
}
return app
}
// func (app *AppInterfaceImpl) InitializeRouter() *mux.Router {
// r := mux.NewRouter()
// return r
// }
// func initialMigration() *gorm.DB {
// dbURI := "host=localhost user=postgres dbname=postgres sslmode=disable password=prakash port=5432"
// var dB *gorm.DB
// dB, err = gorm.Open("postgres", dbURI)
// if err != nil {
// fmt.Println(err.Error())
// panic("Cannot connect to Database")
// } else {
// fmt.Println("Successfully connected to database")
// }
// // defer DB.Close()
// dB.AutoMigrate(&models.Student{})
// dB.AutoMigrate(&models.Teacher{})
// dB.AutoMigrate(&models.Attendance{})
// return dB
// }
func (app *AppInterfaceImpl) Start() {
// dbURI := "host=localhost user=postgres dbname=postgres sslmode=disable password=prakash port=5432"
// var dB *gorm.DB
// dB, err = gorm.Open("postgres", dbURI)
// if err != nil {
// fmt.Println(err.Error())
// panic("Cannot connect to Database")
// } else {
// fmt.Println("Successfully connected to database")
// }
// // defer DB.Close()
// dB.AutoMigrate(&models.Student{})
// dB.AutoMigrate(&models.Teacher{})
// dB.AutoMigrate(&models.Attendance{})
fmt.Println("Initializing Router")
log.Fatal(http.ListenAndServe(":8090", app.MuxRouter))
}