-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
76 lines (62 loc) · 1.62 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
package main
import (
"Rabbit-OJ-Backend/controllers/contest"
"Rabbit-OJ-Backend/controllers/middlewares"
"Rabbit-OJ-Backend/controllers/question"
"Rabbit-OJ-Backend/controllers/submission"
"Rabbit-OJ-Backend/controllers/user"
"Rabbit-OJ-Backend/controllers/websocket"
"Rabbit-OJ-Backend/services/config"
"Rabbit-OJ-Backend/services/initialize"
"Rabbit-OJ-Backend/services/routine"
"Rabbit-OJ-Backend/services/storage/rpc"
"context"
"fmt"
"github.com/Rabbit-OJ/Rabbit-OJ-Tester"
"os"
"github.com/gin-gonic/gin"
)
var (
Role = ""
)
func main() {
config.GlobalContext, config.CancelGlobalContext = context.WithCancel(context.Background())
defer func() {
config.CancelGlobalContext()
}()
Role = os.Getenv("Role")
fmt.Printf("[Role] %s \n", Role)
if Role == "Server" {
initialize.Config()
routine.StartCheck()
initialize.Cert("server")
initialize.Judger(config.GlobalContext)
initialize.DB(config.GlobalContext)
go rpc.Register()
server := gin.Default()
server.Use(middlewares.Cors())
user.Router(server)
submission.Router(server)
question.Router(server)
contest.Router(server)
websocket.WebSocket(server)
err := server.Run(":8888")
if err != nil {
fmt.Println(err)
}
} else if Role == "Judge" {
initialize.Config()
initialize.Cert("client")
initialize.Judger(config.GlobalContext)
initialize.CheckTestCase()
routine.RegisterSignal()
exitChan := make(chan bool)
select {
case <-exitChan:
os.Exit(0)
}
} else if Role == "Tester" {
fmt.Println("[WARN] use v1.0 Tester is deprecated, and will be removed soon, please use v2 Tester instead.")
tester.Tester()
}
}