github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-control-plane/envoy/config/core/v3/backoff.pb.validate.go (about)

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: envoy/config/core/v3/backoff.proto
     3  
     4  package envoy_config_core_v3
     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 BackoffStrategy 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 *BackoffStrategy) Validate() error {
    40  	if m == nil {
    41  		return nil
    42  	}
    43  
    44  	if m.GetBaseInterval() == nil {
    45  		return BackoffStrategyValidationError{
    46  			field:  "BaseInterval",
    47  			reason: "value is required",
    48  		}
    49  	}
    50  
    51  	if d := m.GetBaseInterval(); d != nil {
    52  		dur, err := d.AsDuration(), d.CheckValid()
    53  		if err != nil {
    54  			return BackoffStrategyValidationError{
    55  				field:  "BaseInterval",
    56  				reason: "value is not a valid duration",
    57  				cause:  err,
    58  			}
    59  		}
    60  
    61  		gte := time.Duration(0*time.Second + 1000000*time.Nanosecond)
    62  
    63  		if dur < gte {
    64  			return BackoffStrategyValidationError{
    65  				field:  "BaseInterval",
    66  				reason: "value must be greater than or equal to 1ms",
    67  			}
    68  		}
    69  
    70  	}
    71  
    72  	if d := m.GetMaxInterval(); d != nil {
    73  		dur, err := d.AsDuration(), d.CheckValid()
    74  		if err != nil {
    75  			return BackoffStrategyValidationError{
    76  				field:  "MaxInterval",
    77  				reason: "value is not a valid duration",
    78  				cause:  err,
    79  			}
    80  		}
    81  
    82  		gt := time.Duration(0*time.Second + 0*time.Nanosecond)
    83  
    84  		if dur <= gt {
    85  			return BackoffStrategyValidationError{
    86  				field:  "MaxInterval",
    87  				reason: "value must be greater than 0s",
    88  			}
    89  		}
    90  
    91  	}
    92  
    93  	return nil
    94  }
    95  
    96  // BackoffStrategyValidationError is the validation error returned by
    97  // BackoffStrategy.Validate if the designated constraints aren't met.
    98  type BackoffStrategyValidationError struct {
    99  	field  string
   100  	reason string
   101  	cause  error
   102  	key    bool
   103  }
   104  
   105  // Field function returns field value.
   106  func (e BackoffStrategyValidationError) Field() string { return e.field }
   107  
   108  // Reason function returns reason value.
   109  func (e BackoffStrategyValidationError) Reason() string { return e.reason }
   110  
   111  // Cause function returns cause value.
   112  func (e BackoffStrategyValidationError) Cause() error { return e.cause }
   113  
   114  // Key function returns key value.
   115  func (e BackoffStrategyValidationError) Key() bool { return e.key }
   116  
   117  // ErrorName returns error name.
   118  func (e BackoffStrategyValidationError) ErrorName() string { return "BackoffStrategyValidationError" }
   119  
   120  // Error satisfies the builtin error interface
   121  func (e BackoffStrategyValidationError) Error() string {
   122  	cause := ""
   123  	if e.cause != nil {
   124  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   125  	}
   126  
   127  	key := ""
   128  	if e.key {
   129  		key = "key for "
   130  	}
   131  
   132  	return fmt.Sprintf(
   133  		"invalid %sBackoffStrategy.%s: %s%s",
   134  		key,
   135  		e.field,
   136  		e.reason,
   137  		cause)
   138  }
   139  
   140  var _ error = BackoffStrategyValidationError{}
   141  
   142  var _ interface {
   143  	Field() string
   144  	Reason() string
   145  	Key() bool
   146  	Cause() error
   147  	ErrorName() string
   148  } = BackoffStrategyValidationError{}