You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

489 lines
12 KiB

// Code generated by protoc-gen-validate. DO NOT EDIT.
// source: google/protobuf/struct.proto
package structpb
import (
"bytes"
"errors"
"fmt"
"net"
"net/mail"
"net/url"
"regexp"
"sort"
"strings"
"time"
"unicode/utf8"
"google.golang.org/protobuf/types/known/anypb"
)
// ensure the imports are used
var (
_ = bytes.MinRead
_ = errors.New("")
_ = fmt.Print
_ = utf8.UTFMax
_ = (*regexp.Regexp)(nil)
_ = (*strings.Reader)(nil)
_ = net.IPv4len
_ = time.Duration(0)
_ = (*url.URL)(nil)
_ = (*mail.Address)(nil)
_ = anypb.Any{}
_ = sort.Sort
)
// Validate checks the field values on Struct with the rules defined in the
// proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *Struct) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on Struct with the rules defined in the
// proto definition for this message. If any rules are violated, the result is
// a list of violation errors wrapped in StructMultiError, or nil if none found.
func (m *Struct) ValidateAll() error {
return m.validate(true)
}
func (m *Struct) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
{
sorted_keys := make([]string, len(m.GetFields()))
i := 0
for key := range m.GetFields() {
sorted_keys[i] = key
i++
}
sort.Slice(sorted_keys, func(i, j int) bool { return sorted_keys[i] < sorted_keys[j] })
for _, key := range sorted_keys {
val := m.GetFields()[key]
_ = val
// no validation rules for Fields[key]
if all {
switch v := interface{}(val).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, StructValidationError{
field: fmt.Sprintf("Fields[%v]", key),
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, StructValidationError{
field: fmt.Sprintf("Fields[%v]", key),
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(val).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return StructValidationError{
field: fmt.Sprintf("Fields[%v]", key),
reason: "embedded message failed validation",
cause: err,
}
}
}
}
}
if len(errors) > 0 {
return StructMultiError(errors)
}
return nil
}
// StructMultiError is an error wrapping multiple validation errors returned by
// Struct.ValidateAll() if the designated constraints aren't met.
type StructMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m StructMultiError) Error() string {
var msgs []string
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m StructMultiError) AllErrors() []error { return m }
// StructValidationError is the validation error returned by Struct.Validate if
// the designated constraints aren't met.
type StructValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e StructValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e StructValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e StructValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e StructValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e StructValidationError) ErrorName() string { return "StructValidationError" }
// Error satisfies the builtin error interface
func (e StructValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sStruct.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = StructValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = StructValidationError{}
// Validate checks the field values on Value with the rules defined in the
// proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *Value) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on Value with the rules defined in the
// proto definition for this message. If any rules are violated, the result is
// a list of violation errors wrapped in ValueMultiError, or nil if none found.
func (m *Value) ValidateAll() error {
return m.validate(true)
}
func (m *Value) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
switch m.Kind.(type) {
case *Value_NullValue:
// no validation rules for NullValue
case *Value_NumberValue:
// no validation rules for NumberValue
case *Value_StringValue:
// no validation rules for StringValue
case *Value_BoolValue:
// no validation rules for BoolValue
case *Value_StructValue:
if all {
switch v := interface{}(m.GetStructValue()).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, ValueValidationError{
field: "StructValue",
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, ValueValidationError{
field: "StructValue",
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(m.GetStructValue()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ValueValidationError{
field: "StructValue",
reason: "embedded message failed validation",
cause: err,
}
}
}
case *Value_ListValue:
if all {
switch v := interface{}(m.GetListValue()).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, ValueValidationError{
field: "ListValue",
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, ValueValidationError{
field: "ListValue",
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(m.GetListValue()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ValueValidationError{
field: "ListValue",
reason: "embedded message failed validation",
cause: err,
}
}
}
}
if len(errors) > 0 {
return ValueMultiError(errors)
}
return nil
}
// ValueMultiError is an error wrapping multiple validation errors returned by
// Value.ValidateAll() if the designated constraints aren't met.
type ValueMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m ValueMultiError) Error() string {
var msgs []string
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m ValueMultiError) AllErrors() []error { return m }
// ValueValidationError is the validation error returned by Value.Validate if
// the designated constraints aren't met.
type ValueValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e ValueValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e ValueValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e ValueValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e ValueValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e ValueValidationError) ErrorName() string { return "ValueValidationError" }
// Error satisfies the builtin error interface
func (e ValueValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sValue.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = ValueValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = ValueValidationError{}
// Validate checks the field values on ListValue with the rules defined in the
// proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *ListValue) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on ListValue with the rules defined in
// the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in ListValueMultiError, or nil
// if none found.
func (m *ListValue) ValidateAll() error {
return m.validate(true)
}
func (m *ListValue) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
for idx, item := range m.GetValues() {
_, _ = idx, item
if all {
switch v := interface{}(item).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, ListValueValidationError{
field: fmt.Sprintf("Values[%v]", idx),
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, ListValueValidationError{
field: fmt.Sprintf("Values[%v]", idx),
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ListValueValidationError{
field: fmt.Sprintf("Values[%v]", idx),
reason: "embedded message failed validation",
cause: err,
}
}
}
}
if len(errors) > 0 {
return ListValueMultiError(errors)
}
return nil
}
// ListValueMultiError is an error wrapping multiple validation errors returned
// by ListValue.ValidateAll() if the designated constraints aren't met.
type ListValueMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m ListValueMultiError) Error() string {
var msgs []string
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m ListValueMultiError) AllErrors() []error { return m }
// ListValueValidationError is the validation error returned by
// ListValue.Validate if the designated constraints aren't met.
type ListValueValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e ListValueValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e ListValueValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e ListValueValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e ListValueValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e ListValueValidationError) ErrorName() string { return "ListValueValidationError" }
// Error satisfies the builtin error interface
func (e ListValueValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sListValue.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = ListValueValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = ListValueValidationError{}