github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-control-plane/envoy/type/matcher/metadata.pb.validate.go (about)

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: envoy/type/matcher/metadata.proto
     3  
     4  package envoy_type_matcher
     5  
     6  import (
     7  	"bytes"
     8  	"errors"
     9  	"fmt"
    10  	"net"
    11  	"net/mail"
    12  	"net/url"
    13  	"regexp"
    14  	"strings"
    15  	"time"
    16  	"unicode/utf8"
    17  
    18  	"google.golang.org/protobuf/types/known/anypb"
    19  )
    20  
    21  // ensure the imports are used
    22  var (
    23  	_ = bytes.MinRead
    24  	_ = errors.New("")
    25  	_ = fmt.Print
    26  	_ = utf8.UTFMax
    27  	_ = (*regexp.Regexp)(nil)
    28  	_ = (*strings.Reader)(nil)
    29  	_ = net.IPv4len
    30  	_ = time.Duration(0)
    31  	_ = (*url.URL)(nil)
    32  	_ = (*mail.Address)(nil)
    33  	_ = anypb.Any{}
    34  )
    35  
    36  // Validate checks the field values on MetadataMatcher with the rules defined
    37  // in the proto definition for this message. If any rules are violated, an
    38  // error is returned.
    39  func (m *MetadataMatcher) Validate() error {
    40  	if m == nil {
    41  		return nil
    42  	}
    43  
    44  	if utf8.RuneCountInString(m.GetFilter()) < 1 {
    45  		return MetadataMatcherValidationError{
    46  			field:  "Filter",
    47  			reason: "value length must be at least 1 runes",
    48  		}
    49  	}
    50  
    51  	if len(m.GetPath()) < 1 {
    52  		return MetadataMatcherValidationError{
    53  			field:  "Path",
    54  			reason: "value must contain at least 1 item(s)",
    55  		}
    56  	}
    57  
    58  	for idx, item := range m.GetPath() {
    59  		_, _ = idx, item
    60  
    61  		if v, ok := interface{}(item).(interface{ Validate() error }); ok {
    62  			if err := v.Validate(); err != nil {
    63  				return MetadataMatcherValidationError{
    64  					field:  fmt.Sprintf("Path[%v]", idx),
    65  					reason: "embedded message failed validation",
    66  					cause:  err,
    67  				}
    68  			}
    69  		}
    70  
    71  	}
    72  
    73  	if m.GetValue() == nil {
    74  		return MetadataMatcherValidationError{
    75  			field:  "Value",
    76  			reason: "value is required",
    77  		}
    78  	}
    79  
    80  	if v, ok := interface{}(m.GetValue()).(interface{ Validate() error }); ok {
    81  		if err := v.Validate(); err != nil {
    82  			return MetadataMatcherValidationError{
    83  				field:  "Value",
    84  				reason: "embedded message failed validation",
    85  				cause:  err,
    86  			}
    87  		}
    88  	}
    89  
    90  	return nil
    91  }
    92  
    93  // MetadataMatcherValidationError is the validation error returned by
    94  // MetadataMatcher.Validate if the designated constraints aren't met.
    95  type MetadataMatcherValidationError struct {
    96  	field  string
    97  	reason string
    98  	cause  error
    99  	key    bool
   100  }
   101  
   102  // Field function returns field value.
   103  func (e MetadataMatcherValidationError) Field() string { return e.field }
   104  
   105  // Reason function returns reason value.
   106  func (e MetadataMatcherValidationError) Reason() string { return e.reason }
   107  
   108  // Cause function returns cause value.
   109  func (e MetadataMatcherValidationError) Cause() error { return e.cause }
   110  
   111  // Key function returns key value.
   112  func (e MetadataMatcherValidationError) Key() bool { return e.key }
   113  
   114  // ErrorName returns error name.
   115  func (e MetadataMatcherValidationError) ErrorName() string { return "MetadataMatcherValidationError" }
   116  
   117  // Error satisfies the builtin error interface
   118  func (e MetadataMatcherValidationError) Error() string {
   119  	cause := ""
   120  	if e.cause != nil {
   121  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   122  	}
   123  
   124  	key := ""
   125  	if e.key {
   126  		key = "key for "
   127  	}
   128  
   129  	return fmt.Sprintf(
   130  		"invalid %sMetadataMatcher.%s: %s%s",
   131  		key,
   132  		e.field,
   133  		e.reason,
   134  		cause)
   135  }
   136  
   137  var _ error = MetadataMatcherValidationError{}
   138  
   139  var _ interface {
   140  	Field() string
   141  	Reason() string
   142  	Key() bool
   143  	Cause() error
   144  	ErrorName() string
   145  } = MetadataMatcherValidationError{}
   146  
   147  // Validate checks the field values on MetadataMatcher_PathSegment with the
   148  // rules defined in the proto definition for this message. If any rules are
   149  // violated, an error is returned.
   150  func (m *MetadataMatcher_PathSegment) Validate() error {
   151  	if m == nil {
   152  		return nil
   153  	}
   154  
   155  	switch m.Segment.(type) {
   156  
   157  	case *MetadataMatcher_PathSegment_Key:
   158  
   159  		if utf8.RuneCountInString(m.GetKey()) < 1 {
   160  			return MetadataMatcher_PathSegmentValidationError{
   161  				field:  "Key",
   162  				reason: "value length must be at least 1 runes",
   163  			}
   164  		}
   165  
   166  	default:
   167  		return MetadataMatcher_PathSegmentValidationError{
   168  			field:  "Segment",
   169  			reason: "value is required",
   170  		}
   171  
   172  	}
   173  
   174  	return nil
   175  }
   176  
   177  // MetadataMatcher_PathSegmentValidationError is the validation error returned
   178  // by MetadataMatcher_PathSegment.Validate if the designated constraints
   179  // aren't met.
   180  type MetadataMatcher_PathSegmentValidationError struct {
   181  	field  string
   182  	reason string
   183  	cause  error
   184  	key    bool
   185  }
   186  
   187  // Field function returns field value.
   188  func (e MetadataMatcher_PathSegmentValidationError) Field() string { return e.field }
   189  
   190  // Reason function returns reason value.
   191  func (e MetadataMatcher_PathSegmentValidationError) Reason() string { return e.reason }
   192  
   193  // Cause function returns cause value.
   194  func (e MetadataMatcher_PathSegmentValidationError) Cause() error { return e.cause }
   195  
   196  // Key function returns key value.
   197  func (e MetadataMatcher_PathSegmentValidationError) Key() bool { return e.key }
   198  
   199  // ErrorName returns error name.
   200  func (e MetadataMatcher_PathSegmentValidationError) ErrorName() string {
   201  	return "MetadataMatcher_PathSegmentValidationError"
   202  }
   203  
   204  // Error satisfies the builtin error interface
   205  func (e MetadataMatcher_PathSegmentValidationError) Error() string {
   206  	cause := ""
   207  	if e.cause != nil {
   208  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   209  	}
   210  
   211  	key := ""
   212  	if e.key {
   213  		key = "key for "
   214  	}
   215  
   216  	return fmt.Sprintf(
   217  		"invalid %sMetadataMatcher_PathSegment.%s: %s%s",
   218  		key,
   219  		e.field,
   220  		e.reason,
   221  		cause)
   222  }
   223  
   224  var _ error = MetadataMatcher_PathSegmentValidationError{}
   225  
   226  var _ interface {
   227  	Field() string
   228  	Reason() string
   229  	Key() bool
   230  	Cause() error
   231  	ErrorName() string
   232  } = MetadataMatcher_PathSegmentValidationError{}