...
1
2
3
4 package v2alpha
5
6 import (
7 "bytes"
8 "errors"
9 "fmt"
10 "net"
11 "net/mail"
12 "net/url"
13 "regexp"
14 "sort"
15 "strings"
16 "time"
17 "unicode/utf8"
18
19 "google.golang.org/protobuf/types/known/anypb"
20 )
21
22
23 var (
24 _ = bytes.MinRead
25 _ = errors.New("")
26 _ = fmt.Print
27 _ = utf8.UTFMax
28 _ = (*regexp.Regexp)(nil)
29 _ = (*strings.Reader)(nil)
30 _ = net.IPv4len
31 _ = time.Duration(0)
32 _ = (*url.URL)(nil)
33 _ = (*mail.Address)(nil)
34 _ = anypb.Any{}
35 _ = sort.Sort
36 )
37
38
39
40
41 func (m *ClusterConfig) Validate() error {
42 return m.validate(false)
43 }
44
45
46
47
48
49 func (m *ClusterConfig) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *ClusterConfig) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60 if len(m.GetClusters()) < 1 {
61 err := ClusterConfigValidationError{
62 field: "Clusters",
63 reason: "value must contain at least 1 item(s)",
64 }
65 if !all {
66 return err
67 }
68 errors = append(errors, err)
69 }
70
71 if len(errors) > 0 {
72 return ClusterConfigMultiError(errors)
73 }
74
75 return nil
76 }
77
78
79
80
81 type ClusterConfigMultiError []error
82
83
84 func (m ClusterConfigMultiError) Error() string {
85 var msgs []string
86 for _, err := range m {
87 msgs = append(msgs, err.Error())
88 }
89 return strings.Join(msgs, "; ")
90 }
91
92
93 func (m ClusterConfigMultiError) AllErrors() []error { return m }
94
95
96
97 type ClusterConfigValidationError struct {
98 field string
99 reason string
100 cause error
101 key bool
102 }
103
104
105 func (e ClusterConfigValidationError) Field() string { return e.field }
106
107
108 func (e ClusterConfigValidationError) Reason() string { return e.reason }
109
110
111 func (e ClusterConfigValidationError) Cause() error { return e.cause }
112
113
114 func (e ClusterConfigValidationError) Key() bool { return e.key }
115
116
117 func (e ClusterConfigValidationError) ErrorName() string { return "ClusterConfigValidationError" }
118
119
120 func (e ClusterConfigValidationError) Error() string {
121 cause := ""
122 if e.cause != nil {
123 cause = fmt.Sprintf(" | caused by: %v", e.cause)
124 }
125
126 key := ""
127 if e.key {
128 key = "key for "
129 }
130
131 return fmt.Sprintf(
132 "invalid %sClusterConfig.%s: %s%s",
133 key,
134 e.field,
135 e.reason,
136 cause)
137 }
138
139 var _ error = ClusterConfigValidationError{}
140
141 var _ interface {
142 Field() string
143 Reason() string
144 Key() bool
145 Cause() error
146 ErrorName() string
147 } = ClusterConfigValidationError{}
148
View as plain text