diff --git a/cmd/joj3/conf.go b/cmd/joj3/conf.go index 40dff6b..4f9951f 100644 --- a/cmd/joj3/conf.go +++ b/cmd/joj3/conf.go @@ -10,9 +10,11 @@ import ( ) type Conf struct { - LogLevel int `default:"0"` - OutputPath string `default:"joj3_result.json"` - Stages []struct { + SandboxExecServer string `default:"localhost:5051"` + SandboxToken string `default:""` + LogLevel int `default:"0"` + OutputPath string `default:"joj3_result.json"` + Stages []struct { Name string Executor struct { Name string diff --git a/cmd/joj3/main.go b/cmd/joj3/main.go index e21a52d..b8e0e05 100644 --- a/cmd/joj3/main.go +++ b/cmd/joj3/main.go @@ -5,7 +5,7 @@ import ( "log/slog" "os" - _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors" + "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors" _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/parsers" "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" @@ -77,6 +77,7 @@ func main() { os.Exit(1) } setupSlog(conf) + executors.InitWithConf(conf.SandboxExecServer, conf.SandboxToken) stages := generateStages(conf) defer stage.Cleanup() results := stage.Run(stages) diff --git a/internal/executors/all.go b/internal/executors/all.go index bd860e6..76a7f96 100644 --- a/internal/executors/all.go +++ b/internal/executors/all.go @@ -2,8 +2,13 @@ package executors import ( _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/dummy" - _ "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/sandbox" + "focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/executors/sandbox" ) // this file does nothing but imports to ensure all the init() functions // in the subpackages are called + +// overwrite the default registered executors +func InitWithConf(sandboxExecServer, sandboxToken string) { + sandbox.InitWithConf(sandboxExecServer, sandboxToken) +} diff --git a/internal/executors/sandbox/meta.go b/internal/executors/sandbox/meta.go index 2702646..e984184 100644 --- a/internal/executors/sandbox/meta.go +++ b/internal/executors/sandbox/meta.go @@ -8,9 +8,17 @@ var name = "sandbox" func init() { stage.RegisterExecutor(name, &Sandbox{ - // TODO: read from conf execServer: "localhost:5051", token: "", cachedMap: make(map[string]string), }) } + +// overwrite the default registered executor +func InitWithConf(execServer, token string) { + stage.RegisterExecutor(name, &Sandbox{ + execServer: execServer, + token: token, + cachedMap: make(map[string]string), + }) +}