-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
95 lines (86 loc) · 3.36 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
/*
* API
*
* Generated by genpjrpc: v0.5.0
*
* API version: v0.0.0-unknown
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
*/
package main
import (
"log"
// WARNING!
// Change this to a fully-qualified import path
// once you place this file into your project.
// For example,
//
// sw "github.com/myname/myrepo/go"
//
"example/server/configs"
"example/server/db"
"example/server/handlers"
"example/server/logic"
"example/server/utils"
)
func main() {
config, err := configs.NewConfig("")
if err != nil {
log.Fatal(err)
}
mongoClient, context, cancleFunc := db.SetupMongoDB()
logger := utils.InitLogger()
docker, err := utils.InitializeDockerClient()
if err != nil {
logger.Error(err.Error())
}
defer db.CloseConnection(mongoClient, context, cancleFunc)
testCaseDataCollection := mongoClient.Database(config.Database.Name).Collection(config.Database.MongoCollection.TestCase)
testCaseDataAccessor, err := db.NewTestCaseDataAccessor(testCaseDataCollection, logger)
if err != nil {
logger.Error(err.Error())
}
submissionDataCollection := mongoClient.Database(config.Database.Name).Collection(config.Database.MongoCollection.Submission)
submissionDataAccessor, err := db.NewSubmissionDataAccessor(submissionDataCollection, logger)
if err != nil {
logger.Error(err.Error())
}
problemDataCollection := mongoClient.Database(config.Database.Name).Collection(config.Database.MongoCollection.Problem)
problemDataAccessor, err := db.NewProblemDataAccessor(problemDataCollection, logger)
if err != nil {
logger.Error("fail to create problem data accessor")
}
submissionSnippetDataCollection := mongoClient.Database(config.Database.Name).Collection(config.Database.MongoCollection.SubmissionSnippet)
submissionSnippetDataAccessor := db.NewSubmissionSnippetDataAccessor(submissionSnippetDataCollection, logger)
accountDataCollection := mongoClient.Database(config.Database.Name).Collection(config.Database.MongoCollection.Account)
accountDataAccessor, err := db.NewAccountDataAccessor(accountDataCollection, logger)
if err != nil {
logger.Error("fail to create account data accessor")
}
problemLogic := logic.NewProblemLogic(logger, problemDataAccessor, testCaseDataAccessor, submissionSnippetDataAccessor)
testCaseLogic := logic.NewTestCaseLogic(testCaseDataAccessor, problemDataAccessor, logger)
judgeConfig := &config.Logic.Judge
judge, err := logic.NewJudgeLogic(logger, mongoClient, docker, judgeConfig, submissionDataAccessor, testCaseDataAccessor, problemDataAccessor)
if err != nil {
logger.Error(err.Error())
}
submissionLogic := logic.NewSubmissionLogic(judge, logger, mongoClient, submissionDataAccessor)
submissionSnippetLogic := logic.NewSubmissionSnippetLogic(logger, submissionSnippetDataAccessor, problemDataAccessor)
testCaseAndSubmissionSnippetLogic := logic.NewTestCaseAndSubmissionSnippetLogic(logger, problemDataAccessor, testCaseDataAccessor, submissionSnippetDataAccessor)
tokenLogic, err := logic.NewTokenLogic(logger, accountDataAccessor, config.Token)
if err != nil {
logger.Error(err.Error())
}
accountLogic := logic.NewAccountLogic(logger, accountDataAccessor, tokenLogic)
server := handlers.NewAPIServerHandler(
submissionLogic,
testCaseLogic,
config,
problemLogic,
submissionSnippetLogic,
testCaseAndSubmissionSnippetLogic,
accountLogic,
tokenLogic,
logger,
)
server.Start()
}