Files
threshold/internal/host/options.go
T
Jeff Mitchell 8b1ca4b0b8 Add host IDs to plugin host sets read response (#1568)
This also includes tweaks here and there within the service and repos.
2021-09-28 16:19:32 -04:00

58 lines
1.4 KiB
Go

package host
// GetOpts - iterate the inbound Options and return a struct
func GetOpts(opt ...Option) (options, error) {
opts := getDefaultOptions()
for _, o := range opt {
if err := o(&opts); err != nil {
return opts, err
}
}
return opts, nil
}
// Option - how Options are passed as arguments.
type Option func(*options) error
// options = how options are represented
type options struct {
WithLimit int
WithOrderByCreateTime bool
Ascending bool
WithSetMembers bool
}
func getDefaultOptions() options {
return options{}
}
// WithLimit provides an option to provide a limit. Intentionally allowing
// negative integers. If WithLimit < 0, then unlimited results are
// returned. If WithLimit == 0, then default limits are used for results.
func WithLimit(l int) Option {
return func(o *options) error {
o.WithLimit = l
return nil
}
}
// WithOrderByCreateTime provides an option to specify ordering by the
// CreateTime field.
func WithOrderByCreateTime(ascending bool) Option {
return func(o *options) error {
o.WithOrderByCreateTime = true
o.Ascending = ascending
return nil
}
}
// WithSetMembers controls whether to include set members in a lookup. This will
// always be true for static and may be true for plugin when we have caching,
// but for now this skips API calls on authentication.
func WithSetMembers(with bool) Option {
return func(o *options) error {
o.WithSetMembers = true
return nil
}
}