config

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfigNotFound = errors.New("configuration not found")
	ErrInvalidConfig  = errors.New("invalid configuration")
)

Functions

This section is empty.

Types

type ConfigCenter

type ConfigCenter interface {
	GetKey(key string) any
	Close() error
	GetClient() *viper.Viper
}

ConfigCenter defines the interface for configuration center

func NewConfigCenter

func NewConfigCenter(opts *ConfigCenterOptions) (ConfigCenter, error)

NewConfigCenter creates a new configuration center based on the type

type ConfigCenterOptions

type ConfigCenterOptions struct {
	Type      ConfigCenterType
	Address   string
	Namespace string
	Timeout   time.Duration
	// Consul specific options
	Token string
	// Nacos specific options
	Group       string
	Username    string
	Password    string
	DataID      string
	Path        string
	ContentType string
}

ConfigCenterOptions contains options for configuration center

func NewConfigCenterOptions

func NewConfigCenterOptions(t ConfigCenterType, addr string, Path string, contentType string) *ConfigCenterOptions

type ConfigCenterType

type ConfigCenterType string

ConfigCenterType represents the type of configuration center

const (
	ConfigCenterTypeConsul ConfigCenterType = "consul"
	ConfigCenterTypeNacos  ConfigCenterType = "nacos"
	ConfigCenterTypeLocal  ConfigCenterType = "local"
)

type ConsulConfigCenter

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

ConsulConfigCenter implements ConfigCenter using Consul

func NewConsulConfigCenter

func NewConsulConfigCenter(opts *ConfigCenterOptions) (*ConsulConfigCenter, error)

NewConsulConfigCenter creates a new Consul configuration center

func (*ConsulConfigCenter) Close

func (c *ConsulConfigCenter) Close() error

Close closes the Consul client connection

func (*ConsulConfigCenter) GetClient

func (c *ConsulConfigCenter) GetClient() *viper.Viper

GetClient returns the underlying viper client

func (*ConsulConfigCenter) GetKey

func (c *ConsulConfigCenter) GetKey(key string) any

GetKey retrieves a configuration value from Consul

type LocalConfigCenter

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

LocalConfigCenter implements ConfigCenter for local testing

func NewLocalConfigCenter

func NewLocalConfigCenter(opts *ConfigCenterOptions) (*LocalConfigCenter, error)

func (*LocalConfigCenter) Close

func (c *LocalConfigCenter) Close() error

func (*LocalConfigCenter) GetClient

func (c *LocalConfigCenter) GetClient() *viper.Viper

func (*LocalConfigCenter) GetKey

func (c *LocalConfigCenter) GetKey(key string) any

Jump to

Keyboard shortcuts

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