config

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 12 Imported by: 0

README

配置源

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBootstrapConfig

func GetBootstrapConfig() *conf.Bootstrap

func ListFactories

func ListFactories() []string

ListFactories 返回已注册工厂名称的字母序列表。

func LoadBootstrapConfig

func LoadBootstrapConfig(configPath string) error

LoadBootstrapConfig 加载程序引导配置

func LoadRemoteConfigSourceConfigs

func LoadRemoteConfigSourceConfigs(configPath string) (error, *conf.RemoteConfig)

LoadRemoteConfigSourceConfigs 加载远程配置源的本地配置

func MustRegisterFactory

func MustRegisterFactory(name Type, f Factory)

MustRegisterFactory 等同于 RegisterFactory,但在出错时 panic(适用于 init)。

func NewConfigProvider

func NewConfigProvider(configPath string) (config.Config, error)

NewConfigProvider 创建一个配置

func NewFileConfigSource

func NewFileConfigSource(filePath string) config.Source

NewFileConfigSource 创建一个本地文件配置源

func NewProvider

func NewProvider(cfg *conf.RemoteConfig) (config.Source, error)

NewProvider 使用指定 name 的 Factory 和 cfg 创建 Provider 实例。

func RegisterConfig

func RegisterConfig(c proto.Message)

RegisterConfig 注册配置(去重、并发安全) 传入值应为指针类型,例如 &conf.SomeConfig{}

func RegisterFactory

func RegisterFactory(name Type, f Factory) error

RegisterFactory 注册一个名为 name 的 Factory。 name 不能为空且不可重复;f 不能为 nil。

Types

type Factory

type Factory func(cfg *conf.RemoteConfig) (config.Source, error)

Factory 根据传入的配置创建一个 Provider 实例。

func GetFactory

func GetFactory(name Type) (Factory, bool)

GetFactory 返回已注册的 Factory 及其存在标识。

type Type

type Type string
const (
	// TypeLocalFile is the local file config type.
	TypeLocalFile Type = "file"

	// TypeApollo is the apollo remote config type.
	TypeApollo Type = "apollo"

	// TypeConsul is the consul remote config type.
	TypeConsul Type = "consul"

	// TypeEtcd is the etcd remote config type.
	TypeEtcd Type = "etcd"

	// TypeKubernetes is the kubernetes remote config type.
	TypeKubernetes Type = "kubernetes"

	// TypeNacos is the nacos remote config type.
	TypeNacos Type = "nacos"

	// TypePolaris is the polaris remote config type.
	TypePolaris Type = "polaris"
)

Jump to

Keyboard shortcuts

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