-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresult.go
66 lines (54 loc) · 983 Bytes
/
result.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package commander
import "errors"
type _Result interface {
Code() int
Error() error
Break() bool
setBreak()
}
type _ResultCode struct {
code int
error error
_break bool
}
func (e _ResultCode) Code() int {
return e.code
}
func (e _ResultCode) Error() error {
return e.error
}
func (e _ResultCode) Break() bool {
return e._break || (e.error != nil)
}
func (e *_ResultCode) setBreak() {
e._break = true
}
func newResult(text string) _Result {
return &_ResultCode{error: errors.New(text)}
}
func newResultCode(code int, text ...string) _Result {
var err error
if len(text) != 0 {
err = errors.New(text[0])
}
return &_ResultCode{
code: code,
error: err,
}
}
func newResultError(err error, codes ...int) _Result {
var code int = 0
if len(codes) != 0 {
code = codes[0]
}
return &_ResultCode{
code: code,
error: err,
}
}
func resultPass() _Result {
return &_ResultCode{}
}
func resultBreak() _Result {
return &_ResultCode{_break: true}
}