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

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: envoy/type/token_bucket.proto
     3  
     4  package envoy_type
     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 TokenBucket with the rules defined in
    37  // the proto definition for this message. If any rules are violated, an error
    38  // is returned.
    39  func (m *TokenBucket) Validate() error {
    40  	if m == nil {
    41  		return nil
    42  	}
    43  
    44  	if m.GetMaxTokens() <= 0 {
    45  		return TokenBucketValidationError{
    46  			field:  "MaxTokens",
    47  			reason: "value must be greater than 0",
    48  		}
    49  	}
    50  
    51  	if wrapper := m.GetTokensPerFill(); wrapper != nil {
    52  
    53  		if wrapper.GetValue() <= 0 {
    54  			return TokenBucketValidationError{
    55  				field:  "TokensPerFill",
    56  				reason: "value must be greater than 0",
    57  			}
    58  		}
    59  
    60  	}
    61  
    62  	if m.GetFillInterval() == nil {
    63  		return TokenBucketValidationError{
    64  			field:  "FillInterval",
    65  			reason: "value is required",
    66  		}
    67  	}
    68  
    69  	if d := m.GetFillInterval(); d != nil {
    70  		dur, err := d.AsDuration(), d.CheckValid()
    71  		if err != nil {
    72  			return TokenBucketValidationError{
    73  				field:  "FillInterval",
    74  				reason: "value is not a valid duration",
    75  				cause:  err,
    76  			}
    77  		}
    78  
    79  		gt := time.Duration(0*time.Second + 0*time.Nanosecond)
    80  
    81  		if dur <= gt {
    82  			return TokenBucketValidationError{
    83  				field:  "FillInterval",
    84  				reason: "value must be greater than 0s",
    85  			}
    86  		}
    87  
    88  	}
    89  
    90  	return nil
    91  }
    92  
    93  // TokenBucketValidationError is the validation error returned by
    94  // TokenBucket.Validate if the designated constraints aren't met.
    95  type TokenBucketValidationError struct {
    96  	field  string
    97  	reason string
    98  	cause  error
    99  	key    bool
   100  }
   101  
   102  // Field function returns field value.
   103  func (e TokenBucketValidationError) Field() string { return e.field }
   104  
   105  // Reason function returns reason value.
   106  func (e TokenBucketValidationError) Reason() string { return e.reason }
   107  
   108  // Cause function returns cause value.
   109  func (e TokenBucketValidationError) Cause() error { return e.cause }
   110  
   111  // Key function returns key value.
   112  func (e TokenBucketValidationError) Key() bool { return e.key }
   113  
   114  // ErrorName returns error name.
   115  func (e TokenBucketValidationError) ErrorName() string { return "TokenBucketValidationError" }
   116  
   117  // Error satisfies the builtin error interface
   118  func (e TokenBucketValidationError) 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 %sTokenBucket.%s: %s%s",
   131  		key,
   132  		e.field,
   133  		e.reason,
   134  		cause)
   135  }
   136  
   137  var _ error = TokenBucketValidationError{}
   138  
   139  var _ interface {
   140  	Field() string
   141  	Reason() string
   142  	Key() bool
   143  	Cause() error
   144  	ErrorName() string
   145  } = TokenBucketValidationError{}