1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
// Copyright (c) The go-grpc-middleware Authors.
// Licensed under the Apache License 2.0.
// Copyright 2017 David Ackroyd. All Rights Reserved.
// See LICENSE for licensing terms.
package protovalidate
import (
"golang.org/x/exp/slices"
"google.golang.org/protobuf/reflect/protoreflect"
)
type options struct {
ignoreMessages []protoreflect.MessageType
}
// An Option lets you add options to protovalidate interceptors using With* funcs.
type Option func(*options)
func evaluateOpts(opts []Option) *options {
optCopy := &options{}
for _, o := range opts {
o(optCopy)
}
return optCopy
}
// WithIgnoreMessages sets the messages that should be ignored by the validator. Use with
// caution and ensure validation is performed elsewhere.
func WithIgnoreMessages(msgs ...protoreflect.MessageType) Option {
return func(o *options) {
o.ignoreMessages = msgs
}
}
func (o *options) shouldIgnoreMessage(m protoreflect.MessageType) bool {
return slices.ContainsFunc(o.ignoreMessages, func(t protoreflect.MessageType) bool {
return m == t
})
}
|