Documentation ¶
Index ¶
- func ApplyOption[T any](opt *T, tgt **T)
- func ApplyOptions[O any](opts O, list ...Option[O])
- func AsBool(b *bool, def ...bool) bool
- func AsValue[T any](p *T) T
- func EvalOptions[O any](opts ...Option[*O]) *O
- func PointerTo[T any](v T) *T
- type NestedOptionsProvider
- type Option
- type OptionTargetProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyOption ¶
func ApplyOption[T any](opt *T, tgt **T)
func ApplyOptions ¶
ApplyOptions applies options to an option target O. O must either be a target interface type or a target struct pointer type.
func EvalOptions ¶
EvalOptions applies options to a new options object and returns this object. O must be a struct type.
Types ¶
type NestedOptionsProvider ¶
type NestedOptionsProvider[T any] interface { NestedOptions() T }
NestedOptionsProvider is the interface for a more specific options object to provide access to a nested options object of type T. T must be a pointer type.
type Option ¶
type Option[T any] interface { ApplyTo(T) }
func MapOptionTarget ¶
MapOptionTarget maps the option target interface from B to W, hereby, W must be a subtype of B, which cannot be expressed with Go generics (Type constraint should be W B). If this constraint is not met, there will be a runtime error.
func OptionWrapper ¶
func OptionWrapper[N, O any, P OptionTargetProvider[N, O]](o Option[N]) Option[P]
OptionWrapper genericly wraps a nested option of type Option[N] to an option of type Option[*O], assuming that the nested option source N implements NestedOptionsProvider[N]. P is only a helper type parameter for Go and doesn't need to be given. It is the pointer type for O (P = *O).
create a wrap option function for all wrappable options with
func WrapXXX[O any, P optionutils.OptionTargetProvider[*Options, O]](args...any) optionutils.Option[P] { return optionutils.OptionWrapper[*Options, O, P](WithXXX(args...)) }
where *Options is the type of the pointer type to the options object to be nested.
The outer option functions wrapping the nested one can then be defined as
func WithXXX(h string) Option { return optionutils.WrapXXX[Options](h) }
For an example see package github.com/open-component-model/ocm/pkg/contexts/ocm/resourcetypes/rpi.
func OptionWrapperFunc ¶
type OptionTargetProvider ¶
type OptionTargetProvider[N, O any] interface { NestedOptionsProvider[N] *O }
OptionTargetProvider is helper interface to declare a pointer type (*O) for an options object providing access to a nested options object of type N (must be a pointer type).