go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/server/quota/quotapb/request_entry.pb.validate.go (about)

     1  // Code generated by protoc-gen-validate. DO NOT EDIT.
     2  // source: go.chromium.org/luci/server/quota/quotapb/request_entry.proto
     3  
     4  package quotapb
     5  
     6  import (
     7  	"bytes"
     8  	"errors"
     9  	"fmt"
    10  	"net"
    11  	"net/mail"
    12  	"net/url"
    13  	"regexp"
    14  	"sort"
    15  	"strings"
    16  	"time"
    17  	"unicode/utf8"
    18  
    19  	"google.golang.org/protobuf/types/known/anypb"
    20  )
    21  
    22  // ensure the imports are used
    23  var (
    24  	_ = bytes.MinRead
    25  	_ = errors.New("")
    26  	_ = fmt.Print
    27  	_ = utf8.UTFMax
    28  	_ = (*regexp.Regexp)(nil)
    29  	_ = (*strings.Reader)(nil)
    30  	_ = net.IPv4len
    31  	_ = time.Duration(0)
    32  	_ = (*url.URL)(nil)
    33  	_ = (*mail.Address)(nil)
    34  	_ = anypb.Any{}
    35  	_ = sort.Sort
    36  )
    37  
    38  // Validate checks the field values on RequestDedupKey with the rules defined
    39  // in the proto definition for this message. If any rules are violated, the
    40  // first error encountered is returned, or nil if there are no violations.
    41  func (m *RequestDedupKey) Validate() error {
    42  	return m.validate(false)
    43  }
    44  
    45  // ValidateAll checks the field values on RequestDedupKey with the rules
    46  // defined in the proto definition for this message. If any rules are
    47  // violated, the result is a list of violation errors wrapped in
    48  // RequestDedupKeyMultiError, or nil if none found.
    49  func (m *RequestDedupKey) ValidateAll() error {
    50  	return m.validate(true)
    51  }
    52  
    53  func (m *RequestDedupKey) validate(all bool) error {
    54  	if m == nil {
    55  		return nil
    56  	}
    57  
    58  	var errors []error
    59  
    60  	if strings.Contains(m.GetIdent(), "~") {
    61  		err := RequestDedupKeyValidationError{
    62  			field:  "Ident",
    63  			reason: "value contains substring \"~\"",
    64  		}
    65  		if !all {
    66  			return err
    67  		}
    68  		errors = append(errors, err)
    69  	}
    70  
    71  	if strings.Contains(m.GetRequestId(), "~") {
    72  		err := RequestDedupKeyValidationError{
    73  			field:  "RequestId",
    74  			reason: "value contains substring \"~\"",
    75  		}
    76  		if !all {
    77  			return err
    78  		}
    79  		errors = append(errors, err)
    80  	}
    81  
    82  	if len(errors) > 0 {
    83  		return RequestDedupKeyMultiError(errors)
    84  	}
    85  
    86  	return nil
    87  }
    88  
    89  // RequestDedupKeyMultiError is an error wrapping multiple validation errors
    90  // returned by RequestDedupKey.ValidateAll() if the designated constraints
    91  // aren't met.
    92  type RequestDedupKeyMultiError []error
    93  
    94  // Error returns a concatenation of all the error messages it wraps.
    95  func (m RequestDedupKeyMultiError) Error() string {
    96  	var msgs []string
    97  	for _, err := range m {
    98  		msgs = append(msgs, err.Error())
    99  	}
   100  	return strings.Join(msgs, "; ")
   101  }
   102  
   103  // AllErrors returns a list of validation violation errors.
   104  func (m RequestDedupKeyMultiError) AllErrors() []error { return m }
   105  
   106  // RequestDedupKeyValidationError is the validation error returned by
   107  // RequestDedupKey.Validate if the designated constraints aren't met.
   108  type RequestDedupKeyValidationError struct {
   109  	field  string
   110  	reason string
   111  	cause  error
   112  	key    bool
   113  }
   114  
   115  // Field function returns field value.
   116  func (e RequestDedupKeyValidationError) Field() string { return e.field }
   117  
   118  // Reason function returns reason value.
   119  func (e RequestDedupKeyValidationError) Reason() string { return e.reason }
   120  
   121  // Cause function returns cause value.
   122  func (e RequestDedupKeyValidationError) Cause() error { return e.cause }
   123  
   124  // Key function returns key value.
   125  func (e RequestDedupKeyValidationError) Key() bool { return e.key }
   126  
   127  // ErrorName returns error name.
   128  func (e RequestDedupKeyValidationError) ErrorName() string { return "RequestDedupKeyValidationError" }
   129  
   130  // Error satisfies the builtin error interface
   131  func (e RequestDedupKeyValidationError) Error() string {
   132  	cause := ""
   133  	if e.cause != nil {
   134  		cause = fmt.Sprintf(" | caused by: %v", e.cause)
   135  	}
   136  
   137  	key := ""
   138  	if e.key {
   139  		key = "key for "
   140  	}
   141  
   142  	return fmt.Sprintf(
   143  		"invalid %sRequestDedupKey.%s: %s%s",
   144  		key,
   145  		e.field,
   146  		e.reason,
   147  		cause)
   148  }
   149  
   150  var _ error = RequestDedupKeyValidationError{}
   151  
   152  var _ interface {
   153  	Field() string
   154  	Reason() string
   155  	Key() bool
   156  	Cause() error
   157  	ErrorName() string
   158  } = RequestDedupKeyValidationError{}