-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (60 loc) · 1.76 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
71
72
73
74
75
76
77
package main
import (
// models "attendance/Package/Models"
models "attendance/Models"
repository "attendance/Repository"
rest_handlers "attendance/RestHandlers"
user_routes "attendance/Router"
services "attendance/Services"
"fmt"
"log"
"net/http"
// "encoding/json"
// "github.com/gorilla/mux"
"github.com/gorilla/mux"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/lib/pq"
//"gorm.io/gorm"
)
var err error
type db struct {
db *gorm.DB
}
func main() {
fmt.Println("running main...")
r := mux.NewRouter()
// NewApp(r, dB)
// app := InitializeEvent()
// fmt.Println("inside main.go main function")
// app.Start()
db := initialMigration()
repo := repository.NewRepoImpl(db)
serviceStudent := services.NewStudentServiceImpl(repo)
servicesTeacher := services.NewTeacherServiceImpl(repo)
restHandler := rest_handlers.NewRestHandlerImpl(serviceStudent, servicesTeacher)
userRoutes := user_routes.NewAppRouterInterfaceImpl(restHandler)
// app:= NewApp(r, dB)
// e: InitializeEvent()
userRoutes.InitializeRouter(r)
fmt.Println("initializing router..")
log.Fatal(http.ListenAndServe(":32026", r))
}
func initialMigration() *gorm.DB {
dbURI := "host=postgres-postgresql.devtron-demo user=postgres dbname=postgres sslmode=disable password=prakash port=5432"
//postgres-devtron-demo-postgresql-0
// url := "postgres://postgres:prakash@localhost:5432/postgres?sslmode=disable"
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
}