...

Source file src/github.com/emissary-ingress/emissary/v3/pkg/api/envoy/data/tap/v2alpha/common.pb.validate.go

Documentation: github.com/emissary-ingress/emissary/v3/pkg/api/envoy/data/tap/v2alpha

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

View as plain text