-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (55 loc) · 1.66 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
package main
import (
"database/sql"
"log"
"net/http"
"os"
"forum/server"
_ "github.com/mattn/go-sqlite3"
)
func main() {
db, err := sql.Open("sqlite3", "./server/forum.db")
if err != nil {
log.Fatal("Database conection error")
}
database := &server.DB{
DB: server.CreateDatabase(db),
}
defer db.Close()
// automate the user creation
// for i := 0; i < 100; i++ {
// userData := server.UserData{
// FirstName: "Tan" + strconv.Itoa(i),
// LastName: "Tan" + strconv.Itoa(i),
// Nickname: "Tan" + strconv.Itoa(i),
// Email: "tan" + strconv.Itoa(i) + "@gmail.com",
// Gender: "Male",
// Age: "22",
// Password: "hello123",
// }
// database.RegisterUser(userData)
// }
go server.SendMsgs()
http.HandleFunc("/", database.Home)
http.HandleFunc("/register", database.Register)
http.HandleFunc("/login", database.Login)
http.HandleFunc("/ws", database.WsEndpoint)
http.HandleFunc("/vadidate", database.CheckCookie)
http.HandleFunc("/logout", database.Logout)
http.HandleFunc("/post", database.Post)
http.HandleFunc("/MessageInfo", database.GetMessages)
http.HandleFunc("/Notify", database.Notifications)
http.HandleFunc("/response", database.Response)
http.HandleFunc("/favorite", database.Favorite)
http.HandleFunc("/updateuser", database.UpdateUser)
http.HandleFunc("/updateuserimage", database.UpdateUserImage)
frontend := http.FileServer(http.Dir("./frontend"))
http.Handle("/frontend/", http.StripPrefix("/frontend/", frontend)) // handling the CSS
port := ""
port = os.Getenv("PORT")
if port == "" {
port = "8800"
}
log.Print("Listening on 0.0.0.0:" + port)
log.Fatal(http.ListenAndServe("0.0.0.0:"+port, nil))
}