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

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: envoy/config/core/v3/socket_option.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 SocketOption 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 *SocketOption) Validate() error {
    40  	if m == nil {
    41  		return nil
    42  	}
    43  
    44  	// no validation rules for Description
    45  
    46  	// no validation rules for Level
    47  
    48  	// no validation rules for Name
    49  
    50  	if _, ok := SocketOption_SocketState_name[int32(m.GetState())]; !ok {
    51  		return SocketOptionValidationError{
    52  			field:  "State",
    53  			reason: "value must be one of the defined enum values",
    54  		}
    55  	}
    56  
    57  	switch m.Value.(type) {
    58  
    59  	case *SocketOption_IntValue:
    60  		// no validation rules for IntValue
    61  
    62  	case *SocketOption_BufValue:
    63  		// no validation rules for BufValue
    64  
    65  	default:
    66  		return SocketOptionValidationError{
    67  			field:  "Value",
    68  			reason: "value is required",
    69  		}
    70  
    71  	}
    72  
    73  	return nil
    74  }
    75  
    76  // SocketOptionValidationError is the validation error returned by
    77  // SocketOption.Validate if the designated constraints aren't met.
    78  type SocketOptionValidationError struct {
    79  	field  string
    80  	reason string
    81  	cause  error
    82  	key    bool
    83  }
    84  
    85  // Field function returns field value.
    86  func (e SocketOptionValidationError) Field() string { return e.field }
    87  
    88  // Reason function returns reason value.
    89  func (e SocketOptionValidationError) Reason() string { return e.reason }
    90  
    91  // Cause function returns cause value.
    92  func (e SocketOptionValidationError) Cause() error { return e.cause }
    93  
    94  // Key function returns key value.
    95  func (e SocketOptionValidationError) Key() bool { return e.key }
    96  
    97  // ErrorName returns error name.
    98  func (e SocketOptionValidationError) ErrorName() string { return "SocketOptionValidationError" }
    99  
   100  // Error satisfies the builtin error interface
   101  func (e SocketOptionValidationError) Error() string {
   102  	cause := ""
   103  	if e.cause != nil {
   104  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   105  	}
   106  
   107  	key := ""
   108  	if e.key {
   109  		key = "key for "
   110  	}
   111  
   112  	return fmt.Sprintf(
   113  		"invalid %sSocketOption.%s: %s%s",
   114  		key,
   115  		e.field,
   116  		e.reason,
   117  		cause)
   118  }
   119  
   120  var _ error = SocketOptionValidationError{}
   121  
   122  var _ interface {
   123  	Field() string
   124  	Reason() string
   125  	Key() bool
   126  	Cause() error
   127  	ErrorName() string
   128  } = SocketOptionValidationError{}