-
Notifications
You must be signed in to change notification settings - Fork 38
/
validate.go
82 lines (66 loc) · 1.46 KB
/
validate.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package owl
import "fmt"
type ValidationError interface {
fmt.Stringer
VarItem() *SetVarItem
Error() string
Message() string
Key() string
SpecName() string
Source() string
Code() ValidateErrorType
}
type ValidationErrors []ValidationError
type ValidateErrorType uint8
const (
ValidateErrorVarRequired ValidateErrorType = iota
)
type RequiredError struct {
varItem *SetVarItem
code ValidateErrorType
}
func NewRequiredError(varItem *SetVarItem) *RequiredError {
return &RequiredError{
varItem: varItem,
code: ValidateErrorVarRequired,
}
}
func (e RequiredError) VarItem() *SetVarItem {
return e.varItem
}
func (e RequiredError) Error() string {
return fmt.Sprintf("Error %v: Variable \"%s\" is unresolved but defined as required by \"%s!\" in \"%s\"",
e.Code(),
e.Key(),
e.SpecName(),
e.Source())
}
func (e RequiredError) Message() string {
return e.Error()
}
func (e RequiredError) String() string {
return e.Error()
}
func (e RequiredError) Code() ValidateErrorType {
return e.code
}
func (e RequiredError) Key() string {
return e.varItem.Var.Key
}
func (e RequiredError) SpecName() string {
return e.varItem.Spec.Name
}
func (e RequiredError) Source() string {
if e.varItem.Spec.Operation == nil {
return "-"
}
if e.varItem.Spec.Operation.Source == "" {
return "-"
}
return e.varItem.Spec.Operation.Source
}
// make sure interfaces are satisfied
var (
_ ValidationError = new(RequiredError)
_ error = new(RequiredError)
)