mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
refactor(envexec): minor modification
This commit is contained in:
parent
8c03485866
commit
cf2e097a6b
@ -97,7 +97,7 @@ func (s Status) MarshalJSON() ([]byte, error) {
|
|||||||
// UnmarshalJSON convert string into status
|
// UnmarshalJSON convert string into status
|
||||||
func (s *Status) UnmarshalJSON(b []byte) error {
|
func (s *Status) UnmarshalJSON(b []byte) error {
|
||||||
str := string(b)
|
str := string(b)
|
||||||
v, err := envexec.StringToStatus(str)
|
v, err := envexec.StringToStatus(str[1 : len(str)-1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -144,7 +144,7 @@ func (t FileErrorType) MarshalJSON() ([]byte, error) {
|
|||||||
func (t *FileErrorType) UnmarshalJSON(b []byte) error {
|
func (t *FileErrorType) UnmarshalJSON(b []byte) error {
|
||||||
str := string(b)
|
str := string(b)
|
||||||
v, ok := fileErrorStringReverse[str]
|
v, ok := fileErrorStringReverse[str]
|
||||||
if ok {
|
if !ok {
|
||||||
return fmt.Errorf("%s is not file error type", str)
|
return fmt.Errorf("%s is not file error type", str)
|
||||||
}
|
}
|
||||||
*t = v
|
*t = v
|
||||||
|
|||||||
@ -68,7 +68,7 @@ func prepareCmdFdTTY(c *Cmd, count int, newStoreFile NewStoreFile) (f []*os.File
|
|||||||
var f *os.File
|
var f *os.File
|
||||||
f, err = os.Open(t.Path)
|
f, err = os.Open(t.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to open file %v", t.Path)
|
return nil, nil, fmt.Errorf("failed to open file: %v", t.Path)
|
||||||
}
|
}
|
||||||
files[j] = f
|
files[j] = f
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ func prepareCmdFd(c *Cmd, count int, newFileStore NewStoreFile) (f []*os.File, p
|
|||||||
case *FileInput:
|
case *FileInput:
|
||||||
f, err := os.Open(t.Path)
|
f, err := os.Open(t.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to open file %v", t.Path)
|
return nil, nil, fmt.Errorf("failed to open file: %v", t.Path)
|
||||||
}
|
}
|
||||||
files[j] = f
|
files[j] = f
|
||||||
|
|
||||||
|
|||||||
@ -77,6 +77,6 @@ func StringToStatus(s string) (Status, error) {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
for i, v := range statusToString {
|
for i, v := range statusToString {
|
||||||
stringToStatus["\""+v+"\""] = Status(i)
|
stringToStatus[v] = Status(i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user