registry

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 6 Imported by: 4

Documentation

Overview

Package registry provides a registry for sources and their providers to integrate into the source list

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureProviders

func ConfigureProviders(flags *flag.FlagSet) map[string]Configuration

ConfigureProviders configures the providers and returns a map of their names as keys and their configurations as values.

This is intended to be called ONLY by the registry owner. TODO: Prevent external calls somehow?

func Finalize

func Finalize(confs ...Configuration)

Finalize takes a number of configurations and marks them as loaded, if they support a DynamicConfiguration signaling.

This is intended to be called ONLY by the registry owner. TODO: Prevent external calls somehow?

func Provide

func Provide(conf Configuration) (source.Source, error)

Provide takes a configuration and calls the associated source providers Provide function to provide a source.

func ProvidePreferred added in v0.1.1

func ProvidePreferred(preferredProvider string, confs []Configuration) (source.Source, error)

ProvidePreferred takes a preferred provider key (that aligns with the value returned by the Configuration.JSONKey method) and a list of configurations, and provides the matching source if possible, but will fall back to another source if the preferred source returns an error when trying to provide it.

func Providers

func Providers() map[Configuration]SourceProvider

Providers returns a map of the source configurations as keys and their corresponding providers as values.

func Register

func Register(registerFunc RegisterFunc)

Register makes a source provider available by the provided name.

Types

type Configuration

type Configuration interface {
	// JSONKey returns the JSON key that should be used when marshalling and
	// unmarshalling the configuration into a global/shared configuration JSON
	// representation. Due to the nature of the global/shared status, this key
	// should be "unique", so as not to overwrite/clash with other provider
	// configurations.
	JSONKey() string
}

Configuration defines a generic SourceProvider's configuration structure.

Implementations may wish to implement the json.Marshaler and json.Unmarshaler interfaces to customize their JSON representations.

type DynamicConfiguration

type DynamicConfiguration interface {
	Configuration
	json.Unmarshaler

	// Finalize is a method called on a configuration when loading is completed.
	//
	// The intent is to be able signal to the configuration that its been loaded
	// so that it can perform any necessary post-load processes, such as
	// validation, normalization, or having values fall-back to defaults.
	Finalize()
}

DynamicConfiguration defines a generic SourceProvider's configuration structure that allows for a dynamic loading mechanism.

type RegisterFunc

type RegisterFunc func(*flag.FlagSet) (SourceProvider, Configuration)

RegisterFunc is the function that allows SourceProviders to define and expose their configuration structure to the registry, so that sources can be provided with a dynamically initialized configuration.

type SourceProvider

type SourceProvider interface {
	// Name returns a printable user-friendly name to refer to the source by.
	Name() string

	// Provide returns a source based on a given configuration.
	Provide(Configuration) (source.Source, error)
}

SourceProvider defines the interface for providers of sources.

Jump to

Keyboard shortcuts

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