style: rename Result -> ExecutorResult
This commit is contained in:
		
							parent
							
								
									8162c63b44
								
							
						
					
					
						commit
						a3deb3d974
					
				
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							|  | @ -36,22 +36,22 @@ The program parse the TOML file to run multiple stages. | ||||||
| 
 | 
 | ||||||
| Each stage contains a executor and parser. | Each stage contains a executor and parser. | ||||||
| 
 | 
 | ||||||
| Executor takes a `Cmd` and returns a `Result`. | Executor takes a `Cmd` and returns a `ExecutorResult`. | ||||||
| 
 | 
 | ||||||
| Parser takes a `Result` and its config and returns a `ParserResult`. | Parser takes a `ExecutorResult` and its config and returns a `ParserResult`. | ||||||
| 
 | 
 | ||||||
| ### `Cmd` | ### `Cmd` | ||||||
| 
 | 
 | ||||||
| Check <https://github.com/criyle/go-judge#rest-api-interface>. | Check `Cmd` in <https://github.com/criyle/go-judge#rest-api-interface>. | ||||||
| 
 | 
 | ||||||
| Some extra fields: | Some extra fields: | ||||||
| 
 | 
 | ||||||
| -   `CopyInCwd bool`: set to `true` to add everything in the current working directory to `CopyIn`. | -   `CopyInCwd bool`: set to `true` to add everything in the current working directory to `CopyIn`. | ||||||
| -   `CopyInCached map[string]string`: key: file name in sandbox, value: file name used in `CopyOutCached`. | -   `CopyInCached map[string]string`: key: file name in sandbox, value: file name used in `CopyOutCached`. | ||||||
| 
 | 
 | ||||||
| ### `Result` | ### `ExecutorResult` | ||||||
| 
 | 
 | ||||||
| Check <https://github.com/criyle/go-judge#rest-api-interface>. | Check `Result` in <https://github.com/criyle/go-judge#rest-api-interface>. | ||||||
| 
 | 
 | ||||||
| ### `ParserResult` | ### `ParserResult` | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,8 +7,8 @@ import ( | ||||||
| 
 | 
 | ||||||
| type Dummy struct{} | type Dummy struct{} | ||||||
| 
 | 
 | ||||||
| func (e *Dummy) Run(stage.Cmd) (*stage.Result, error) { | func (e *Dummy) Run(stage.Cmd) (*stage.ExecutorResult, error) { | ||||||
| 	return &stage.Result{ | 	return &stage.ExecutorResult{ | ||||||
| 		Status:     stage.Status(envexec.StatusInvalid), | 		Status:     stage.Status(envexec.StatusInvalid), | ||||||
| 		ExitStatus: 0, | 		ExitStatus: 0, | ||||||
| 		Error:      "I'm a dummy", | 		Error:      "I'm a dummy", | ||||||
|  |  | ||||||
|  | @ -105,10 +105,10 @@ func convertPBFile(i stage.CmdFile) *pb.Request_File { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func convertPBResult(res []*pb.Response_Result) []stage.Result { | func convertPBResult(res []*pb.Response_Result) []stage.ExecutorResult { | ||||||
| 	var ret []stage.Result | 	var ret []stage.ExecutorResult | ||||||
| 	for _, r := range res { | 	for _, r := range res { | ||||||
| 		ret = append(ret, stage.Result{ | 		ret = append(ret, stage.ExecutorResult{ | ||||||
| 			Status:     stage.Status(r.Status), | 			Status:     stage.Status(r.Status), | ||||||
| 			ExitStatus: int(r.ExitStatus), | 			ExitStatus: int(r.ExitStatus), | ||||||
| 			Error:      r.Error, | 			Error:      r.Error, | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ type Sandbox struct { | ||||||
| 	cachedMap  map[string]string | 	cachedMap  map[string]string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (e *Sandbox) Run(cmd stage.Cmd) (*stage.Result, error) { | func (e *Sandbox) Run(cmd stage.Cmd) (*stage.ExecutorResult, error) { | ||||||
| 	slog.Info("sandbox run", "cmd", cmd) | 	slog.Info("sandbox run", "cmd", cmd) | ||||||
| 	if cmd.CopyIn == nil { | 	if cmd.CopyIn == nil { | ||||||
| 		cmd.CopyIn = make(map[string]stage.CmdFile) | 		cmd.CopyIn = make(map[string]stage.CmdFile) | ||||||
|  |  | ||||||
|  | @ -15,7 +15,7 @@ type Config struct { | ||||||
| 
 | 
 | ||||||
| type Dummy struct{} | type Dummy struct{} | ||||||
| 
 | 
 | ||||||
| func (e *Dummy) Run(result *stage.Result, configAny any) ( | func (e *Dummy) Run(result *stage.ExecutorResult, configAny any) ( | ||||||
| 	*stage.ParserResult, error, | 	*stage.ParserResult, error, | ||||||
| ) { | ) { | ||||||
| 	var config Config | 	var config Config | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ package stage | ||||||
| var executorMap = map[string]Executor{} | var executorMap = map[string]Executor{} | ||||||
| 
 | 
 | ||||||
| type Executor interface { | type Executor interface { | ||||||
| 	Run(Cmd) (*Result, error) | 	Run(Cmd) (*ExecutorResult, error) | ||||||
| 	Cleanup() error | 	Cleanup() error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -104,8 +104,8 @@ func (s *Status) UnmarshalJSON(b []byte) error { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Result defines single command result
 | // ExecutorResult defines single command result
 | ||||||
| type Result struct { | type ExecutorResult struct { | ||||||
| 	Status     Status            `json:"status"` | 	Status     Status            `json:"status"` | ||||||
| 	ExitStatus int               `json:"exitStatus"` | 	ExitStatus int               `json:"exitStatus"` | ||||||
| 	Error      string            `json:"error,omitempty"` | 	Error      string            `json:"error,omitempty"` | ||||||
|  | @ -119,7 +119,7 @@ type Result struct { | ||||||
| 	Buffs map[string][]byte `json:"-"` | 	Buffs map[string][]byte `json:"-"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (r Result) String() string { | func (r ExecutorResult) String() string { | ||||||
| 	type Result struct { | 	type Result struct { | ||||||
| 		Status     Status | 		Status     Status | ||||||
| 		ExitStatus int | 		ExitStatus int | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ package stage | ||||||
| var parserMap = map[string]Parser{} | var parserMap = map[string]Parser{} | ||||||
| 
 | 
 | ||||||
| type Parser interface { | type Parser interface { | ||||||
| 	Run(*Result, any) (*ParserResult, error) | 	Run(*ExecutorResult, any) (*ParserResult, error) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func RegisterParser(name string, parser Parser) { | func RegisterParser(name string, parser Parser) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user