forked from TaHB-CS-Project/Combined
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
122 lines (101 loc) · 3.64 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"database/sql"
"fmt"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
_ "github.com/lib/pq"
)
//for deployment
var (
host = os.Getenv("PostgresDBHost")
port = os.Getenv("PostgresDBPort")
user = os.Getenv("PostgresDBUser")
password = os.Getenv("PostgresDBPassword")
dbname = os.Getenv("PostgresDBUser")
)
// testing locally on port 8090
// var (
// host = goDotEnvVariable("PostgresDBHost")
// port = goDotEnvVariable("PostgresDBPort")
// user = goDotEnvVariable("PostgresDBUser")
// password = goDotEnvVariable("PostgresDBPassword")
// dbname = goDotEnvVariable("PostgresDBUser")
// )
func goDotEnvVariable(key string) string {
// load .env file
err := godotenv.Load("db.env")
if err != nil {
log.Fatalf("Error loading .env file")
}
return os.Getenv(key)
}
// declare global db to use across other files
var db *sql.DB
func main() {
//start database instance for use
initDB()
initstyle()
http.HandleFunc("/", Index)
http.HandleFunc("/signin", Login)
http.HandleFunc("/logout", Logout)
http.HandleFunc("/create-account_registerd.html", Create_account_registerd)
http.HandleFunc("/create-account.html", Create_account)
http.HandleFunc("/create_account", SignUp)
http.HandleFunc("/forgot-password-submit.html", Forgot_password_submit)
http.HandleFunc("/forgot-password.html", Forgot_password)
//User
http.HandleFunc("/user_add-record.html", user_add_record)
http.HandleFunc("/create_record", create_record)
http.HandleFunc("/save_record", create_record_draft)
http.HandleFunc("/user_dashboard.html", user_dashboard)
http.HandleFunc("/user_diagnosis.html", user_diagnosis)
http.HandleFunc("/user_procedure.html", user_procedure)
http.HandleFunc("/user_record-draft.html", user_record_draft)
http.HandleFunc("/user_record-list.html", user_record_list)
http.HandleFunc("/submit_record_draft", submit_record_draft)
http.HandleFunc("/delete_record_draft", delete_record_draft)
//Hospital Admin
http.HandleFunc("/hospital_admin_dashboard.html", hospital_admin_dashboard)
http.HandleFunc("/hospital_admin_diagnosis.html", hospital_admin_diagnosis)
http.HandleFunc("/hospital_admin_procedure.html", hospital_admin_procedure)
http.HandleFunc("/hospital_admin_record-list.html", hospital_admin_record_list)
http.HandleFunc("/hospital_admin_staff-list.html", hospital_admin_staff_list)
//Admin
http.HandleFunc("/admin_dashboard.html", admin_dashboard)
http.HandleFunc("/admin_diagnosis.html", admin_diagnosis)
http.HandleFunc("/admin_procedure.html", admin_procedure)
http.HandleFunc("/admin_record-list.html", admin_record_list)
http.HandleFunc("/admin_staff-list.html", admin_staff_list)
http.HandleFunc("/admin_create-account-second.html", admin_create_account_second)
http.HandleFunc("/create_account_second", Hospitaladmin_signup)
log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), nil))
}
//initalize connection to the DB
func initDB() {
var err error
psqlInfo := fmt.Sprintf("host=%s port=%s user=%s "+
"password=%s dbname=%s sslmode=disable",
host, port, user, password, dbname)
db, err = sql.Open("postgres", psqlInfo)
if err != nil {
panic(err)
}
}
//initialize frontend javascript, style, img, fonts
func initstyle() {
http.Handle("/css/", //final url can be anything
http.StripPrefix("/css/",
http.FileServer(http.Dir("css"))))
http.Handle("/img/", //final url can be anything
http.StripPrefix("/img/",
http.FileServer(http.Dir("img"))))
http.Handle("/fonts/", //final url can be anything
http.StripPrefix("/fonts/",
http.FileServer(http.Dir("fonts"))))
http.Handle("/js/", //final url can be anything
http.StripPrefix("/js/",
http.FileServer(http.Dir("js"))))
}