Co-authored-by: Todd Knight <T.Alan.Knight@gmail.com> Co-authored-by: Jeff Mitchell <jeffrey.mitchell@gmail.com> Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
32 lines
784 B
Go
32 lines
784 B
Go
package handlers
|
|
|
|
// getOpts - iterate the inbound Options and return a struct
|
|
func getOpts(opt ...Option) options {
|
|
opts := getDefaultOptions()
|
|
for _, o := range opt {
|
|
o(&opts)
|
|
}
|
|
return opts
|
|
}
|
|
|
|
// Option - how Options are passed as arguments
|
|
type Option func(*options)
|
|
|
|
// options = how options are represented
|
|
type options struct {
|
|
withDiscardUnknownFields bool
|
|
}
|
|
|
|
func getDefaultOptions() options {
|
|
return options{}
|
|
}
|
|
|
|
// WithDiscardUnknownFields provides an option to cause StructToProto to ignore
|
|
// unknown fields. This is useful in some instances when we need to unmarshal a
|
|
// value from a pb.Struct after we've added some custom extra fields.
|
|
func WithDiscardUnknownFields(discard bool) Option {
|
|
return func(o *options) {
|
|
o.withDiscardUnknownFields = discard
|
|
}
|
|
}
|