github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/go-control-plane/envoy/config/common/dynamic_forward_proxy/v2alpha/dns_cache.pb.validate.go (about)

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: envoy/config/common/dynamic_forward_proxy/v2alpha/dns_cache.proto
     3  
     4  package envoy_config_common_dynamic_forward_proxy_v2alpha
     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  	v2 "github.com/hxx258456/ccgo/go-control-plane/envoy/api/v2"
    21  )
    22  
    23  // ensure the imports are used
    24  var (
    25  	_ = bytes.MinRead
    26  	_ = errors.New("")
    27  	_ = fmt.Print
    28  	_ = utf8.UTFMax
    29  	_ = (*regexp.Regexp)(nil)
    30  	_ = (*strings.Reader)(nil)
    31  	_ = net.IPv4len
    32  	_ = time.Duration(0)
    33  	_ = (*url.URL)(nil)
    34  	_ = (*mail.Address)(nil)
    35  	_ = anypb.Any{}
    36  
    37  	_ = v2.Cluster_DnsLookupFamily(0)
    38  )
    39  
    40  // Validate checks the field values on DnsCacheConfig with the rules defined in
    41  // the proto definition for this message. If any rules are violated, an error
    42  // is returned.
    43  func (m *DnsCacheConfig) Validate() error {
    44  	if m == nil {
    45  		return nil
    46  	}
    47  
    48  	if len(m.GetName()) < 1 {
    49  		return DnsCacheConfigValidationError{
    50  			field:  "Name",
    51  			reason: "value length must be at least 1 bytes",
    52  		}
    53  	}
    54  
    55  	if _, ok := v2.Cluster_DnsLookupFamily_name[int32(m.GetDnsLookupFamily())]; !ok {
    56  		return DnsCacheConfigValidationError{
    57  			field:  "DnsLookupFamily",
    58  			reason: "value must be one of the defined enum values",
    59  		}
    60  	}
    61  
    62  	if d := m.GetDnsRefreshRate(); d != nil {
    63  		dur, err := d.AsDuration(), d.CheckValid()
    64  		if err != nil {
    65  			return DnsCacheConfigValidationError{
    66  				field:  "DnsRefreshRate",
    67  				reason: "value is not a valid duration",
    68  				cause:  err,
    69  			}
    70  		}
    71  
    72  		gte := time.Duration(0*time.Second + 1000000*time.Nanosecond)
    73  
    74  		if dur < gte {
    75  			return DnsCacheConfigValidationError{
    76  				field:  "DnsRefreshRate",
    77  				reason: "value must be greater than or equal to 1ms",
    78  			}
    79  		}
    80  
    81  	}
    82  
    83  	if d := m.GetHostTtl(); d != nil {
    84  		dur, err := d.AsDuration(), d.CheckValid()
    85  		if err != nil {
    86  			return DnsCacheConfigValidationError{
    87  				field:  "HostTtl",
    88  				reason: "value is not a valid duration",
    89  				cause:  err,
    90  			}
    91  		}
    92  
    93  		gt := time.Duration(0*time.Second + 0*time.Nanosecond)
    94  
    95  		if dur <= gt {
    96  			return DnsCacheConfigValidationError{
    97  				field:  "HostTtl",
    98  				reason: "value must be greater than 0s",
    99  			}
   100  		}
   101  
   102  	}
   103  
   104  	if wrapper := m.GetMaxHosts(); wrapper != nil {
   105  
   106  		if wrapper.GetValue() <= 0 {
   107  			return DnsCacheConfigValidationError{
   108  				field:  "MaxHosts",
   109  				reason: "value must be greater than 0",
   110  			}
   111  		}
   112  
   113  	}
   114  
   115  	if v, ok := interface{}(m.GetDnsFailureRefreshRate()).(interface{ Validate() error }); ok {
   116  		if err := v.Validate(); err != nil {
   117  			return DnsCacheConfigValidationError{
   118  				field:  "DnsFailureRefreshRate",
   119  				reason: "embedded message failed validation",
   120  				cause:  err,
   121  			}
   122  		}
   123  	}
   124  
   125  	return nil
   126  }
   127  
   128  // DnsCacheConfigValidationError is the validation error returned by
   129  // DnsCacheConfig.Validate if the designated constraints aren't met.
   130  type DnsCacheConfigValidationError struct {
   131  	field  string
   132  	reason string
   133  	cause  error
   134  	key    bool
   135  }
   136  
   137  // Field function returns field value.
   138  func (e DnsCacheConfigValidationError) Field() string { return e.field }
   139  
   140  // Reason function returns reason value.
   141  func (e DnsCacheConfigValidationError) Reason() string { return e.reason }
   142  
   143  // Cause function returns cause value.
   144  func (e DnsCacheConfigValidationError) Cause() error { return e.cause }
   145  
   146  // Key function returns key value.
   147  func (e DnsCacheConfigValidationError) Key() bool { return e.key }
   148  
   149  // ErrorName returns error name.
   150  func (e DnsCacheConfigValidationError) ErrorName() string { return "DnsCacheConfigValidationError" }
   151  
   152  // Error satisfies the builtin error interface
   153  func (e DnsCacheConfigValidationError) Error() string {
   154  	cause := ""
   155  	if e.cause != nil {
   156  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   157  	}
   158  
   159  	key := ""
   160  	if e.key {
   161  		key = "key for "
   162  	}
   163  
   164  	return fmt.Sprintf(
   165  		"invalid %sDnsCacheConfig.%s: %s%s",
   166  		key,
   167  		e.field,
   168  		e.reason,
   169  		cause)
   170  }
   171  
   172  var _ error = DnsCacheConfigValidationError{}
   173  
   174  var _ interface {
   175  	Field() string
   176  	Reason() string
   177  	Key() bool
   178  	Cause() error
   179  	ErrorName() string
   180  } = DnsCacheConfigValidationError{}