...
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 *MutexStats) Validate() error {
42 return m.validate(false)
43 }
44
45
46
47
48
49 func (m *MutexStats) ValidateAll() error {
50 return m.validate(true)
51 }
52
53 func (m *MutexStats) validate(all bool) error {
54 if m == nil {
55 return nil
56 }
57
58 var errors []error
59
60
61
62
63
64
65
66 if len(errors) > 0 {
67 return MutexStatsMultiError(errors)
68 }
69
70 return nil
71 }
72
73
74
75 type MutexStatsMultiError []error
76
77
78 func (m MutexStatsMultiError) Error() string {
79 var msgs []string
80 for _, err := range m {
81 msgs = append(msgs, err.Error())
82 }
83 return strings.Join(msgs, "; ")
84 }
85
86
87 func (m MutexStatsMultiError) AllErrors() []error { return m }
88
89
90
91 type MutexStatsValidationError struct {
92 field string
93 reason string
94 cause error
95 key bool
96 }
97
98
99 func (e MutexStatsValidationError) Field() string { return e.field }
100
101
102 func (e MutexStatsValidationError) Reason() string { return e.reason }
103
104
105 func (e MutexStatsValidationError) Cause() error { return e.cause }
106
107
108 func (e MutexStatsValidationError) Key() bool { return e.key }
109
110
111 func (e MutexStatsValidationError) ErrorName() string { return "MutexStatsValidationError" }
112
113
114 func (e MutexStatsValidationError) Error() string {
115 cause := ""
116 if e.cause != nil {
117 cause = fmt.Sprintf(" | caused by: %v", e.cause)
118 }
119
120 key := ""
121 if e.key {
122 key = "key for "
123 }
124
125 return fmt.Sprintf(
126 "invalid %sMutexStats.%s: %s%s",
127 key,
128 e.field,
129 e.reason,
130 cause)
131 }
132
133 var _ error = MutexStatsValidationError{}
134
135 var _ interface {
136 Field() string
137 Reason() string
138 Key() bool
139 Cause() error
140 ErrorName() string
141 } = MutexStatsValidationError{}
142
View as plain text