provider

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package provider defines the config source abstraction.

Providers load configuration from various sources (file, consul, etcd, etc.) and support watching for changes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileProvider

type FileProvider struct {
	// contains filtered or unexported fields
}

FileProvider loads config from a local file and watches for changes.

func NewFileProvider

func NewFileProvider(path string) (*FileProvider, error)

NewFileProvider creates a provider that reads from a local file.

func (*FileProvider) Close

func (p *FileProvider) Close() error

Close stops watching and releases resources.

func (*FileProvider) Load

func (p *FileProvider) Load(ctx context.Context) ([]byte, error)

Load reads the config file.

func (*FileProvider) Path added in v1.12.0

func (p *FileProvider) Path() string

Path returns the path to the config file.

func (*FileProvider) Type

func (p *FileProvider) Type() Type

Type returns TypeFile.

func (*FileProvider) Watch

func (p *FileProvider) Watch(ctx context.Context) (<-chan struct{}, error)

Watch starts watching the config file for changes. Returns a channel that receives a value when the file changes.

type Provider

type Provider interface {
	// Type returns the provider type for logging/debugging.
	Type() Type

	// Load reads raw config bytes from the source.
	Load(ctx context.Context) ([]byte, error)

	// Watch starts watching for changes and signals via the returned channel.
	// The channel receives a value when config changes.
	// Cancel the context to stop watching.
	// Returns nil channel if watching is not supported.
	Watch(ctx context.Context) (<-chan struct{}, error)

	// Close releases any resources held by the provider.
	Close() error
}

Provider abstracts config sources.

Implementations must be safe for concurrent use.

func New

func New(opts ProviderConfig) (Provider, error)

New creates a Provider based on ProviderConfig.

type ProviderConfig

type ProviderConfig struct {
	// Type specifies the provider type (file, consul, etcd, zookeeper).
	Type Type

	// Path is the config path (file path or key path).
	Path string

	// Endpoints for remote providers (consul, etcd, zookeeper).
	Endpoints []string
}

ProviderConfig configures provider creation.

type Type

type Type string

Type identifies the config source type.

const (
	TypeFile      Type = "file"
	TypeConsul    Type = "consul"
	TypeEtcd      Type = "etcd"
	TypeZookeeper Type = "zookeeper"
)

func ParseType

func ParseType(s string) (Type, error)

ParseType converts a string to a Type.

Jump to

Keyboard shortcuts

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