Debian Codegraph @

go/xds/core/v3/cidr.pb.validate.go

raw symbols SCIP
1 // Code generated by protoc-gen-validate. DO NOT EDIT.
2 // source: xds/core/v3/cidr.proto
3
4 package v3
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 // ensure the imports are used
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 // Validate checks the field values on CidrRange with the rules defined in the
39 // proto definition for this message. If any rules are violated, the first
40 // error encountered is returned, or nil if there are no violations.
41 func (m *CidrRange) Validate() error {
42 return m.validate(false)
43 }
44
45 // ValidateAll checks the field values on CidrRange with the rules defined in
46 // the proto definition for this message. If any rules are violated, the
47 // result is a list of violation errors wrapped in CidrRangeMultiError, or nil
48 // if none found.
49 func (m *CidrRange) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *CidrRange) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60 if utf8.RuneCountInString(m.GetAddressPrefix()) < 1 {
61 err := CidrRangeValidationError{
62 field: "AddressPrefix",
63 reason: "value length must be at least 1 runes",
64 }
65 if !all {
66 return err
67 }
68 errors = append(errors, err)
69 }
70
71 if wrapper := m.GetPrefixLen(); wrapper != nil {
72
73 if wrapper.GetValue() > 128 {
74 err := CidrRangeValidationError{
75 field: "PrefixLen",
76 reason: "value must be less than or equal to 128",
77 }
78 if !all {
79 return err
80 }
81 errors = append(errors, err)
82 }
83
84 }
85
86 if len(errors) > 0 {
87 return CidrRangeMultiError(errors)
88 }
89
90 return nil
91 }
92
93 // CidrRangeMultiError is an error wrapping multiple validation errors returned
94 // by CidrRange.ValidateAll() if the designated constraints aren't met.
95 type CidrRangeMultiError []error
96
97 // Error returns a concatenation of all the error messages it wraps.
98 func (m CidrRangeMultiError) Error() string {
99 msgs := make([]string, 0, len(m))
100 for _, err := range m {
101 msgs = append(msgs, err.Error())
102 }
103 return strings.Join(msgs, "; ")
104 }
105
106 // AllErrors returns a list of validation violation errors.
107 func (m CidrRangeMultiError) AllErrors() []error { return m }
108
109 // CidrRangeValidationError is the validation error returned by
110 // CidrRange.Validate if the designated constraints aren't met.
111 type CidrRangeValidationError struct {
112 field string
113 reason string
114 cause error
115 key bool
116 }
117
118 // Field function returns field value.
119 func (e CidrRangeValidationError) Field() string { return e.field }
120
121 // Reason function returns reason value.
122 func (e CidrRangeValidationError) Reason() string { return e.reason }
123
124 // Cause function returns cause value.
125 func (e CidrRangeValidationError) Cause() error { return e.cause }
126
127 // Key function returns key value.
128 func (e CidrRangeValidationError) Key() bool { return e.key }
129
130 // ErrorName returns error name.
131 func (e CidrRangeValidationError) ErrorName() string { return "CidrRangeValidationError" }
132
133 // Error satisfies the builtin error interface
134 func (e CidrRangeValidationError) Error() string {
135 cause := ""
136 if e.cause != nil {
137 cause = fmt.Sprintf(" | caused by: %v", e.cause)
138 }
139
140 key := ""
141 if e.key {
142 key = "key for "
143 }
144
145 return fmt.Sprintf(
146 "invalid %sCidrRange.%s: %s%s",
147 key,
148 e.field,
149 e.reason,
150 cause)
151 }
152
153 var _ error = CidrRangeValidationError{}
154
155 var _ interface {
156 Field() string
157 Reason() string
158 Key() bool
159 Cause() error
160 ErrorName() string
161 } = CidrRangeValidationError{}