-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (51 loc) · 1.43 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
package main
import (
"fmt"
"github.com/Carter907/go-solve/db"
"github.com/Carter907/go-solve/handlers"
"github.com/Carter907/go-solve/model"
"github.com/Carter907/go-solve/service"
"log"
"net/http"
"os"
)
func main() {
fmt.Println("starting go-solve on http://localhost:8080")
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
fs := http.FileServer(http.Dir("static/"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
db.NewConnection()
tasks := service.GetAllTasks()
user := &model.User{
ID: 0,
Username: "",
Password: "",
}
currTaskIndex := 0
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
handlers.BaseHandler(w, r, tasks, user)
})
http.HandleFunc("/editor", func(w http.ResponseWriter, r *http.Request) {
handlers.EditorHandler(w, r, tasks, &currTaskIndex)
})
http.HandleFunc("/run-code", func(w http.ResponseWriter, r *http.Request) {
handlers.RunCodeHandler(w, r, &tasks[currTaskIndex], user)
})
http.HandleFunc("/signup", func(w http.ResponseWriter, r *http.Request) {
handlers.SignupHandler(w, r)
})
http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
handlers.LoginHandler(w, r, user)
})
http.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
handlers.LogoutHandler(w, r, user)
})
err := http.ListenAndServe(":"+port, nil)
if err != nil {
log.Fatalln("Failed to run the server:", err)
return
}
}