config

package
v0.0.0-...-fdc0f55 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultValidator = validator.New(validator.WithRequiredStructEnabled())

DefaultValidator is the default validator used by the config package.

Functions

func LoadForStruct

func LoadForStruct[T any](
	ctx context.Context,
	target target.Target,
	userInput map[string]any,
) (T, error)

LoadForStruct loads the given user input map into the given struct and validates it.

Types

type GetConfigProviderByName

type GetConfigProviderByName func(name string) (Provider, bool)

GetConfigProviderByName gets a provider by name.

type LoadAndValidateParams

type LoadAndValidateParams[T any] func(ctx context.Context, target target.Target, userInput map[string]any) (T, error)

LoadAndValidateParams restores and validates the parameters from the given user input map.

type Provider

type Provider interface {
	// Name - name of the provider.
	Name() string
	// Resolve - resolves the configuration for the given target and user input map.
	Resolve(ctx context.Context, target target.Target, userInput map[string]any) (string, error)
	// contains filtered or unexported methods
}

Provider provides a configuration.

func Provide

func Provide[T any](
	name string,
	loader LoadAndValidateParams[T],
	resolver ResolveConfig[T],
) Provider

Provide creates a config provider using the loader and resolver functions.

type ProviderRegistry

type ProviderRegistry interface {
	// Register - registers a config provider.
	Register(provider Provider) ProviderRegistry
	// GetByName - gets a provider by name.
	GetByName(name string) (Provider, bool)
	// GetNames - gets the names of all registered providers.
	GetNames() []string
}

ProviderRegistry is a registry of configuration providers.

func NewRegistry

func NewRegistry() ProviderRegistry

type ResolveConfig

type ResolveConfig[T any] func(ctx context.Context, target target.Target, params T) (string, error)

ResolveConfig resolves the configuration for the given target and parameters.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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