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

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: envoy/extensions/common/dynamic_forward_proxy/v3/dns_cache.proto
     3  
     4  package envoy_extensions_common_dynamic_forward_proxy_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  	v3 "github.com/hxx258456/ccgo/go-control-plane/envoy/config/cluster/v3"
    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  	_ = v3.Cluster_DnsLookupFamily(0)
    38  )
    39  
    40  // Validate checks the field values on DnsCacheCircuitBreakers with the rules
    41  // defined in the proto definition for this message. If any rules are
    42  // violated, an error is returned.
    43  func (m *DnsCacheCircuitBreakers) Validate() error {
    44  	if m == nil {
    45  		return nil
    46  	}
    47  
    48  	if v, ok := interface{}(m.GetMaxPendingRequests()).(interface{ Validate() error }); ok {
    49  		if err := v.Validate(); err != nil {
    50  			return DnsCacheCircuitBreakersValidationError{
    51  				field:  "MaxPendingRequests",
    52  				reason: "embedded message failed validation",
    53  				cause:  err,
    54  			}
    55  		}
    56  	}
    57  
    58  	return nil
    59  }
    60  
    61  // DnsCacheCircuitBreakersValidationError is the validation error returned by
    62  // DnsCacheCircuitBreakers.Validate if the designated constraints aren't met.
    63  type DnsCacheCircuitBreakersValidationError struct {
    64  	field  string
    65  	reason string
    66  	cause  error
    67  	key    bool
    68  }
    69  
    70  // Field function returns field value.
    71  func (e DnsCacheCircuitBreakersValidationError) Field() string { return e.field }
    72  
    73  // Reason function returns reason value.
    74  func (e DnsCacheCircuitBreakersValidationError) Reason() string { return e.reason }
    75  
    76  // Cause function returns cause value.
    77  func (e DnsCacheCircuitBreakersValidationError) Cause() error { return e.cause }
    78  
    79  // Key function returns key value.
    80  func (e DnsCacheCircuitBreakersValidationError) Key() bool { return e.key }
    81  
    82  // ErrorName returns error name.
    83  func (e DnsCacheCircuitBreakersValidationError) ErrorName() string {
    84  	return "DnsCacheCircuitBreakersValidationError"
    85  }
    86  
    87  // Error satisfies the builtin error interface
    88  func (e DnsCacheCircuitBreakersValidationError) Error() string {
    89  	cause := ""
    90  	if e.cause != nil {
    91  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
    92  	}
    93  
    94  	key := ""
    95  	if e.key {
    96  		key = "key for "
    97  	}
    98  
    99  	return fmt.Sprintf(
   100  		"invalid %sDnsCacheCircuitBreakers.%s: %s%s",
   101  		key,
   102  		e.field,
   103  		e.reason,
   104  		cause)
   105  }
   106  
   107  var _ error = DnsCacheCircuitBreakersValidationError{}
   108  
   109  var _ interface {
   110  	Field() string
   111  	Reason() string
   112  	Key() bool
   113  	Cause() error
   114  	ErrorName() string
   115  } = DnsCacheCircuitBreakersValidationError{}
   116  
   117  // Validate checks the field values on DnsCacheConfig with the rules defined in
   118  // the proto definition for this message. If any rules are violated, an error
   119  // is returned.
   120  func (m *DnsCacheConfig) Validate() error {
   121  	if m == nil {
   122  		return nil
   123  	}
   124  
   125  	if utf8.RuneCountInString(m.GetName()) < 1 {
   126  		return DnsCacheConfigValidationError{
   127  			field:  "Name",
   128  			reason: "value length must be at least 1 runes",
   129  		}
   130  	}
   131  
   132  	if _, ok := v3.Cluster_DnsLookupFamily_name[int32(m.GetDnsLookupFamily())]; !ok {
   133  		return DnsCacheConfigValidationError{
   134  			field:  "DnsLookupFamily",
   135  			reason: "value must be one of the defined enum values",
   136  		}
   137  	}
   138  
   139  	if d := m.GetDnsRefreshRate(); d != nil {
   140  		dur, err := d.AsDuration(), d.CheckValid()
   141  		if err != nil {
   142  			return DnsCacheConfigValidationError{
   143  				field:  "DnsRefreshRate",
   144  				reason: "value is not a valid duration",
   145  				cause:  err,
   146  			}
   147  		}
   148  
   149  		gte := time.Duration(0*time.Second + 1000000*time.Nanosecond)
   150  
   151  		if dur < gte {
   152  			return DnsCacheConfigValidationError{
   153  				field:  "DnsRefreshRate",
   154  				reason: "value must be greater than or equal to 1ms",
   155  			}
   156  		}
   157  
   158  	}
   159  
   160  	if d := m.GetHostTtl(); d != nil {
   161  		dur, err := d.AsDuration(), d.CheckValid()
   162  		if err != nil {
   163  			return DnsCacheConfigValidationError{
   164  				field:  "HostTtl",
   165  				reason: "value is not a valid duration",
   166  				cause:  err,
   167  			}
   168  		}
   169  
   170  		gt := time.Duration(0*time.Second + 0*time.Nanosecond)
   171  
   172  		if dur <= gt {
   173  			return DnsCacheConfigValidationError{
   174  				field:  "HostTtl",
   175  				reason: "value must be greater than 0s",
   176  			}
   177  		}
   178  
   179  	}
   180  
   181  	if wrapper := m.GetMaxHosts(); wrapper != nil {
   182  
   183  		if wrapper.GetValue() <= 0 {
   184  			return DnsCacheConfigValidationError{
   185  				field:  "MaxHosts",
   186  				reason: "value must be greater than 0",
   187  			}
   188  		}
   189  
   190  	}
   191  
   192  	if v, ok := interface{}(m.GetDnsFailureRefreshRate()).(interface{ Validate() error }); ok {
   193  		if err := v.Validate(); err != nil {
   194  			return DnsCacheConfigValidationError{
   195  				field:  "DnsFailureRefreshRate",
   196  				reason: "embedded message failed validation",
   197  				cause:  err,
   198  			}
   199  		}
   200  	}
   201  
   202  	if v, ok := interface{}(m.GetDnsCacheCircuitBreaker()).(interface{ Validate() error }); ok {
   203  		if err := v.Validate(); err != nil {
   204  			return DnsCacheConfigValidationError{
   205  				field:  "DnsCacheCircuitBreaker",
   206  				reason: "embedded message failed validation",
   207  				cause:  err,
   208  			}
   209  		}
   210  	}
   211  
   212  	// no validation rules for UseTcpForDnsLookups
   213  
   214  	if v, ok := interface{}(m.GetDnsResolutionConfig()).(interface{ Validate() error }); ok {
   215  		if err := v.Validate(); err != nil {
   216  			return DnsCacheConfigValidationError{
   217  				field:  "DnsResolutionConfig",
   218  				reason: "embedded message failed validation",
   219  				cause:  err,
   220  			}
   221  		}
   222  	}
   223  
   224  	if v, ok := interface{}(m.GetTypedDnsResolverConfig()).(interface{ Validate() error }); ok {
   225  		if err := v.Validate(); err != nil {
   226  			return DnsCacheConfigValidationError{
   227  				field:  "TypedDnsResolverConfig",
   228  				reason: "embedded message failed validation",
   229  				cause:  err,
   230  			}
   231  		}
   232  	}
   233  
   234  	for idx, item := range m.GetPreresolveHostnames() {
   235  		_, _ = idx, item
   236  
   237  		if v, ok := interface{}(item).(interface{ Validate() error }); ok {
   238  			if err := v.Validate(); err != nil {
   239  				return DnsCacheConfigValidationError{
   240  					field:  fmt.Sprintf("PreresolveHostnames[%v]", idx),
   241  					reason: "embedded message failed validation",
   242  					cause:  err,
   243  				}
   244  			}
   245  		}
   246  
   247  	}
   248  
   249  	if d := m.GetDnsQueryTimeout(); d != nil {
   250  		dur, err := d.AsDuration(), d.CheckValid()
   251  		if err != nil {
   252  			return DnsCacheConfigValidationError{
   253  				field:  "DnsQueryTimeout",
   254  				reason: "value is not a valid duration",
   255  				cause:  err,
   256  			}
   257  		}
   258  
   259  		gt := time.Duration(0*time.Second + 0*time.Nanosecond)
   260  
   261  		if dur <= gt {
   262  			return DnsCacheConfigValidationError{
   263  				field:  "DnsQueryTimeout",
   264  				reason: "value must be greater than 0s",
   265  			}
   266  		}
   267  
   268  	}
   269  
   270  	if v, ok := interface{}(m.GetKeyValueConfig()).(interface{ Validate() error }); ok {
   271  		if err := v.Validate(); err != nil {
   272  			return DnsCacheConfigValidationError{
   273  				field:  "KeyValueConfig",
   274  				reason: "embedded message failed validation",
   275  				cause:  err,
   276  			}
   277  		}
   278  	}
   279  
   280  	return nil
   281  }
   282  
   283  // DnsCacheConfigValidationError is the validation error returned by
   284  // DnsCacheConfig.Validate if the designated constraints aren't met.
   285  type DnsCacheConfigValidationError struct {
   286  	field  string
   287  	reason string
   288  	cause  error
   289  	key    bool
   290  }
   291  
   292  // Field function returns field value.
   293  func (e DnsCacheConfigValidationError) Field() string { return e.field }
   294  
   295  // Reason function returns reason value.
   296  func (e DnsCacheConfigValidationError) Reason() string { return e.reason }
   297  
   298  // Cause function returns cause value.
   299  func (e DnsCacheConfigValidationError) Cause() error { return e.cause }
   300  
   301  // Key function returns key value.
   302  func (e DnsCacheConfigValidationError) Key() bool { return e.key }
   303  
   304  // ErrorName returns error name.
   305  func (e DnsCacheConfigValidationError) ErrorName() string { return "DnsCacheConfigValidationError" }
   306  
   307  // Error satisfies the builtin error interface
   308  func (e DnsCacheConfigValidationError) Error() string {
   309  	cause := ""
   310  	if e.cause != nil {
   311  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   312  	}
   313  
   314  	key := ""
   315  	if e.key {
   316  		key = "key for "
   317  	}
   318  
   319  	return fmt.Sprintf(
   320  		"invalid %sDnsCacheConfig.%s: %s%s",
   321  		key,
   322  		e.field,
   323  		e.reason,
   324  		cause)
   325  }
   326  
   327  var _ error = DnsCacheConfigValidationError{}
   328  
   329  var _ interface {
   330  	Field() string
   331  	Reason() string
   332  	Key() bool
   333  	Cause() error
   334  	ErrorName() string
   335  } = DnsCacheConfigValidationError{}