Files
threshold/sdk/plugins/options.go
T
429247f407 [COMPLIANCE] Update Copyright Headers (#6282)
* [COMPLIANCE] Update Copyright and License Headers

* chore: make gen to generate files with copyright headers

* chore: update missed copyright headers

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Justin Nguyen <justin.nguyen@hashicorp.com>
2026-01-28 11:05:07 -06:00

57 lines
1.3 KiB
Go

// Copyright IBM Corp. 2020, 2025
// SPDX-License-Identifier: MPL-2.0
package external_plugins
import (
"fmt"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-secure-stdlib/pluginutil/v2"
)
// getOpts iterates the inbound Options and returns a struct
func getOpts(opt ...Option) (*options, error) {
opts := getDefaultOptions()
for _, o := range opt {
if o == nil {
continue
}
if err := o(opts); err != nil {
return nil, fmt.Errorf("error running option function: %w", err)
}
}
return opts, nil
}
// Option - a type that wraps an interface for compile-time safety but can
// contain an option for this package or for wrappers implementing this
// interface.
type Option func(*options) error
type options struct {
withPluginOptions []pluginutil.Option
withLogger hclog.Logger
}
func getDefaultOptions() *options {
return &options{}
}
// WithPluginOptions allows providing plugin-related (as opposed to
// configutil-related) options
func WithPluginOptions(opts ...pluginutil.Option) Option {
return func(o *options) error {
o.withPluginOptions = append(o.withPluginOptions, opts...)
return nil
}
}
// WithLogger allows passing a logger to the plugin library for debugging
func WithLogger(logger hclog.Logger) Option {
return func(o *options) error {
o.withLogger = logger
return nil
}
}