registry

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2024 License: Apache-2.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetOptions

func SetOptions[T any](entity T, optSetters ...func(T) (T, error)) (T, error)

Types

type ConfigOption

type ConfigOption[T any, TOption Option] struct {
	// contains filtered or unexported fields
}

func BoolConfigOption

func BoolConfigOption[T any](name, description string, defaultVal bool, setter func(T, bool) (T, error)) *ConfigOption[T, bool]

func DurationConfigOption

func DurationConfigOption[T any](name, description string, defaultVal time.Duration, setter func(T, time.Duration) (T, error)) *ConfigOption[T, time.Duration]

func IntConfigOption

func IntConfigOption[T any](name, description string, defaultVal int, setter func(T, int) (T, error)) *ConfigOption[T, int]

func StringConfigOption

func StringConfigOption[T any](name, description string, defaultVal string, setter func(T, string) (T, error)) *ConfigOption[T, string]

func StringSliceConfigOption

func StringSliceConfigOption[T any](name, description string, defaultVal []string, setter func(T, []string) (T, error)) *ConfigOption[T, []string]

func (*ConfigOption[T, TOption]) DefaultVal

func (co *ConfigOption[T, TOption]) DefaultVal() TOption

func (*ConfigOption[T, TOption]) Description

func (co *ConfigOption[T, TOption]) Description() string

func (*ConfigOption[T, TOption]) Name

func (co *ConfigOption[T, TOption]) Name() string

func (*ConfigOption[T, TOption]) SetPrefix

func (co *ConfigOption[T, TOption]) SetPrefix(prefix string)

func (*ConfigOption[T, TOption]) Setter

func (co *ConfigOption[T, TOption]) Setter() func(T, TOption) (T, error)

type Configurer

type Configurer interface {
	Description() string
	Name() string
	SetPrefix(string)
}

type Entry

type Entry[T any] struct {
	Factory FactoryFunc[T]
	Name    string
	Options []Configurer
}

Entry contains information about each of the Entities in the Registry including the factory function, name, and configurable options

type FactoryFunc

type FactoryFunc[T any] func() T

FactoryFunc is a function that will create an instantiation of an Entity

type Option

type Option interface {
	int | string | []string | bool | time.Duration
}

type Registry

type Registry[T any] struct {
	// contains filtered or unexported fields
}

Registry is a way for the library to expose details about available configuration options for a collection of Entities at run time. This is useful to do things such as expose attestor configuration options to Witness CLI. This lets the CLI create flags for all the available options at run time.

func New

func New[T any]() Registry[T]

New returns a new instance of a Registry

func (Registry[T]) AllEntries

func (r Registry[T]) AllEntries() []Entry[T]

AllEntries returns every Entry in the Registry

func (Registry[T]) Entry

func (r Registry[T]) Entry(name string) (Entry[T], bool)

Entry returns the Registry Entry for an Entity with the provided name. If an entity with the provided name cannot be found in the Registry, the boolean return value will be false.

func (Registry[T]) NewEntity

func (r Registry[T]) NewEntity(name string, optSetters ...func(T) (T, error)) (T, error)

NewEntity creates a new entity with the the default options set

func (Registry[T]) Options

func (r Registry[T]) Options(name string) ([]Configurer, bool)

Options returns all of the available options an Entity with the provided name. If an Entity with the provided name cannot be found in the Registry the boolean return value will be false.

func (Registry[T]) Register

func (r Registry[T]) Register(name string, factoryFunc FactoryFunc[T], opts ...Configurer) Entry[T]

Register adds an Entry to the Registry for an Entity

func (Registry[T]) SetDefaultVals

func (r Registry[T]) SetDefaultVals(entity T, opts []Configurer) (T, error)

SetDefaultVals will take an Entity and call Setter for every option with that option's defaultVal.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL