blob: f00265e8e676d8ebf87e997542051b77cfa86d13 (
plain)
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
|
package main
import (
"errors"
"time"
)
const (
resultSuccess = "success"
resultCompileError = "compile_error"
resultRuntimeError = "runtime_error"
resultTimeout = "timeout"
resultInternalError = "internal_error"
)
var (
errInvalidMaxDuration = errors.New("'max_duration_ms' must be positive")
)
type execRequestData struct {
Code string `json:"code"`
CodeHash string `json:"code_hash"`
Stdin string `json:"stdin"`
MaxDurationMilliseconds int `json:"max_duration_ms"`
}
func (req *execRequestData) maxDuration() time.Duration {
return time.Duration(req.MaxDurationMilliseconds) * time.Millisecond
}
func (req *execRequestData) validate() error {
if req.MaxDurationMilliseconds <= 0 {
return errInvalidMaxDuration
}
return nil
}
type execResponseData struct {
Status string `json:"status"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
}
func (res *execResponseData) success() bool {
return res.Status == resultSuccess
}
|