style: rename config -> conf for consistency
This commit is contained in:
		
							parent
							
								
									380762a2e3
								
							
						
					
					
						commit
						8e49684abe
					
				
							
								
								
									
										4
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
									
									
									
									
								
							|  | @ -1,10 +1,10 @@ | ||||||
| .PHONY: all clean test | .PHONY: all clean test | ||||||
| 
 | 
 | ||||||
| BUILD_DIR = ./build | BUILD_DIR = ./build | ||||||
| APP_NAME = joj3 | APPS := $(notdir $(wildcard ./cmd/*)) | ||||||
| 
 | 
 | ||||||
| all: | all: | ||||||
| 	go build -o $(BUILD_DIR)/$(APP_NAME) ./cmd/$(APP_NAME) | 	$(foreach APP,$(APPS), go build -o $(BUILD_DIR)/$(APP) ./cmd/$(APP);) | ||||||
| 
 | 
 | ||||||
| clean: | clean: | ||||||
| 	rm -rf $(BUILD_DIR)/* | 	rm -rf $(BUILD_DIR)/* | ||||||
|  |  | ||||||
|  | @ -46,7 +46,7 @@ Each stage contains a executor and parser. | ||||||
| 
 | 
 | ||||||
| Executor takes a `Cmd` and returns a `ExecutorResult`. | Executor takes a `Cmd` and returns a `ExecutorResult`. | ||||||
| 
 | 
 | ||||||
| Parser takes a `ExecutorResult` and its config and returns a `ParserResult` and `bool` to indicate whether we should skip the rest stages. | Parser takes a `ExecutorResult` and its conf and returns a `ParserResult` and `bool` to indicate whether we should skip the rest stages. | ||||||
| 
 | 
 | ||||||
| ### `Cmd` | ### `Cmd` | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -68,7 +68,7 @@ func parseConfFile(path string) Conf { | ||||||
| 	conf := Conf{} | 	conf := Conf{} | ||||||
| 	err := m.Load(&conf) | 	err := m.Load(&conf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		slog.Error("parse stages config", "error", err) | 		slog.Error("parse stages conf", "error", err) | ||||||
| 		os.Exit(1) | 		os.Exit(1) | ||||||
| 	} | 	} | ||||||
| 	return conf | 	return conf | ||||||
|  |  | ||||||
|  | @ -51,13 +51,13 @@ func generateStages(conf Conf) []stage.Stage { | ||||||
| 		if len(s.Executor.With.Cases) == 0 { | 		if len(s.Executor.With.Cases) == 0 { | ||||||
| 			cmds = []stage.Cmd{defaultCmd} | 			cmds = []stage.Cmd{defaultCmd} | ||||||
| 		} | 		} | ||||||
| 		slog.Debug("parse stages config", "cmds", cmds) | 		slog.Debug("parse stages conf", "cmds", cmds) | ||||||
| 		stages = append(stages, stage.Stage{ | 		stages = append(stages, stage.Stage{ | ||||||
| 			Name:         s.Name, | 			Name:         s.Name, | ||||||
| 			ExecutorName: s.Executor.Name, | 			ExecutorName: s.Executor.Name, | ||||||
| 			ExecutorCmds: cmds, | 			ExecutorCmds: cmds, | ||||||
| 			ParserName:   s.Parser.Name, | 			ParserName:   s.Parser.Name, | ||||||
| 			ParserConfig: s.Parser.With, | 			ParserConf:   s.Parser.With, | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 	return stages | 	return stages | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ var name = "sandbox" | ||||||
| 
 | 
 | ||||||
| func init() { | func init() { | ||||||
| 	stage.RegisterExecutor(name, &Sandbox{ | 	stage.RegisterExecutor(name, &Sandbox{ | ||||||
| 		// TODO: read from config
 | 		// TODO: read from conf
 | ||||||
| 		execClient: createExecClient("localhost:5051", ""), | 		execClient: createExecClient("localhost:5051", ""), | ||||||
| 		cachedMap:  make(map[string]string), | 		cachedMap:  make(map[string]string), | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
|  | @ -7,7 +7,7 @@ import ( | ||||||
| 	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | 	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type Config struct { | type Conf struct { | ||||||
| 	Cases []struct { | 	Cases []struct { | ||||||
| 		Score      int | 		Score      int | ||||||
| 		StdoutPath string | 		StdoutPath string | ||||||
|  | @ -16,27 +16,27 @@ type Config struct { | ||||||
| 
 | 
 | ||||||
| type Diff struct{} | type Diff struct{} | ||||||
| 
 | 
 | ||||||
| func (*Diff) Run(results []stage.ExecutorResult, configAny any) ( | func (*Diff) Run(results []stage.ExecutorResult, confAny any) ( | ||||||
| 	[]stage.ParserResult, bool, error, | 	[]stage.ParserResult, bool, error, | ||||||
| ) { | ) { | ||||||
| 	config, err := stage.DecodeConfig[Config](configAny) | 	conf, err := stage.DecodeConf[Conf](confAny) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, true, err | 		return nil, true, err | ||||||
| 	} | 	} | ||||||
| 	if len(config.Cases) != len(results) { | 	if len(conf.Cases) != len(results) { | ||||||
| 		return nil, true, fmt.Errorf("cases number not match") | 		return nil, true, fmt.Errorf("cases number not match") | ||||||
| 	} | 	} | ||||||
| 	var res []stage.ParserResult | 	var res []stage.ParserResult | ||||||
| 	for i, caseConfig := range config.Cases { | 	for i, caseConf := range conf.Cases { | ||||||
| 		result := results[i] | 		result := results[i] | ||||||
| 		score := 0 | 		score := 0 | ||||||
| 		stdout, err := os.ReadFile(caseConfig.StdoutPath) | 		stdout, err := os.ReadFile(caseConf.StdoutPath) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, true, err | 			return nil, true, err | ||||||
| 		} | 		} | ||||||
| 		// TODO: more compare strategies
 | 		// TODO: more compare strategies
 | ||||||
| 		if string(stdout) == result.Files["stdout"] { | 		if string(stdout) == result.Files["stdout"] { | ||||||
| 			score = caseConfig.Score | 			score = caseConf.Score | ||||||
| 		} | 		} | ||||||
| 		res = append(res, stage.ParserResult{ | 		res = append(res, stage.ParserResult{ | ||||||
| 			Score: score, | 			Score: score, | ||||||
|  |  | ||||||
|  | @ -6,27 +6,27 @@ import ( | ||||||
| 	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | 	"focs.ji.sjtu.edu.cn/git/FOCS-dev/JOJ3/internal/stage" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type Config struct { | type Conf struct { | ||||||
| 	Score   int | 	Score   int | ||||||
| 	Comment string | 	Comment string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type Dummy struct{} | type Dummy struct{} | ||||||
| 
 | 
 | ||||||
| func (*Dummy) Run(results []stage.ExecutorResult, configAny any) ( | func (*Dummy) Run(results []stage.ExecutorResult, confAny any) ( | ||||||
| 	[]stage.ParserResult, bool, error, | 	[]stage.ParserResult, bool, error, | ||||||
| ) { | ) { | ||||||
| 	config, err := stage.DecodeConfig[Config](configAny) | 	conf, err := stage.DecodeConf[Conf](confAny) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, true, err | 		return nil, true, err | ||||||
| 	} | 	} | ||||||
| 	var res []stage.ParserResult | 	var res []stage.ParserResult | ||||||
| 	for _, result := range results { | 	for _, result := range results { | ||||||
| 		res = append(res, stage.ParserResult{ | 		res = append(res, stage.ParserResult{ | ||||||
| 			Score: config.Score, | 			Score: conf.Score, | ||||||
| 			Comment: fmt.Sprintf( | 			Comment: fmt.Sprintf( | ||||||
| 				"%s, executor status: run time: %d ns, memory: %d bytes", | 				"%s, executor status: run time: %d ns, memory: %d bytes", | ||||||
| 				config.Comment, result.RunTime, result.Memory, | 				conf.Comment, result.RunTime, result.Memory, | ||||||
| 			), | 			), | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -7,15 +7,15 @@ import ( | ||||||
| 	"github.com/criyle/go-judge/envexec" | 	"github.com/criyle/go-judge/envexec" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type Config struct{} | type Conf struct{} | ||||||
| 
 | 
 | ||||||
| type ResultStatus struct{} | type ResultStatus struct{} | ||||||
| 
 | 
 | ||||||
| func (*ResultStatus) Run(results []stage.ExecutorResult, configAny any) ( | func (*ResultStatus) Run(results []stage.ExecutorResult, confAny any) ( | ||||||
| 	[]stage.ParserResult, bool, error, | 	[]stage.ParserResult, bool, error, | ||||||
| ) { | ) { | ||||||
| 	// TODO: more config options
 | 	// TODO: more conf options
 | ||||||
| 	_, err := stage.DecodeConfig[Config](configAny) | 	_, err := stage.DecodeConf[Conf](confAny) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, true, err | 		return nil, true, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -155,7 +155,7 @@ type Stage struct { | ||||||
| 	ExecutorName string | 	ExecutorName string | ||||||
| 	ExecutorCmds []Cmd | 	ExecutorCmds []Cmd | ||||||
| 	ParserName   string | 	ParserName   string | ||||||
| 	ParserConfig any | 	ParserConf   any | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type ParserResult struct { | type ParserResult struct { | ||||||
|  |  | ||||||
|  | @ -19,9 +19,9 @@ func Run(stages []Stage) []StageResult { | ||||||
| 			break | 			break | ||||||
| 		} | 		} | ||||||
| 		slog.Debug("executor run done", "results", executorResults) | 		slog.Debug("executor run done", "results", executorResults) | ||||||
| 		slog.Debug("parser run start", "config", stage.ParserConfig) | 		slog.Debug("parser run start", "conf", stage.ParserConf) | ||||||
| 		parser := parserMap[stage.ParserName] | 		parser := parserMap[stage.ParserName] | ||||||
| 		parserResults, end, err := parser.Run(executorResults, stage.ParserConfig) | 		parserResults, end, err := parser.Run(executorResults, stage.ParserConf) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			slog.Error("parser run error", "name", stage.ExecutorName, "error", err) | 			slog.Error("parser run error", "name", stage.ExecutorName, "error", err) | ||||||
| 			break | 			break | ||||||
|  |  | ||||||
|  | @ -2,11 +2,11 @@ package stage | ||||||
| 
 | 
 | ||||||
| import "github.com/mitchellh/mapstructure" | import "github.com/mitchellh/mapstructure" | ||||||
| 
 | 
 | ||||||
| func DecodeConfig[T any](configAny any) (*T, error) { | func DecodeConf[T any](confAny any) (*T, error) { | ||||||
| 	var config T | 	var conf T | ||||||
| 	err := mapstructure.Decode(configAny, &config) | 	err := mapstructure.Decode(confAny, &conf) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	return &config, nil | 	return &conf, nil | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user