Documentation
¶
Overview ¶
Package config contains generated code by adptool.
Package config provides adapters for Kratos config types and functions.
Index ¶
- Constants
- Variables
- func As(d interfaces.Config, target any) bool
- func Load(configPath string, target interface{}) (kratosconfig.Config, error)
- func NewConfig(cfg *sourcev1.Sources, opts ...options.Option) (interfaces.Config, error)
- func NewKConfig(opts ...config.Option) config.Config
- func Register(name string, sourceFactory any)
- func RegisterSourceFactory(name string, factory SourceFactory)
- func RegisterSourceFunc(name string, factory SourceFunc)
- func WithConfigOption(opts ...config.Option) options.Option
- func WithEnvPrefixes(prefixes ...string) options.Option
- func WithKDecoder(d config.Decoder) config.Option
- func WithKMergeFunc(m config.Merge) config.Option
- func WithKResolveActualTypes(enableConvertToType bool) config.Option
- func WithKResolver(r config.Resolver) config.Option
- func WithKSource(s ...config.Source) config.Option
- func WithSource(s ...config.Source) options.Option
- type BuildFunc
- type Builder
- type FileConfig
- type KConfig
- type KDecoder
- type KKeyValue
- type KMerge
- type KObserver
- type KOption
- type KReader
- type KResolver
- type KSource
- type KValue
- type KWatcher
- type Options
- type ProtoSyncer
- type SourceFactory
- type SourceFunc
- type SourceType
- type Syncer
Constants ¶
const Module = "config"
Variables ¶
var (
ErrInvalidConfigType = runtimeerrors.NewStructured(Module, "invalid config type")
)
var ErrNotFound = config.ErrNotFound
Functions ¶
func As ¶ added in v0.2.6
func As(d interfaces.Config, target any) bool
As finds the first decoder in the chain that matches the type of target. If a match is found, it sets target to that decoder value and returns true.
The chain consists of d itself, followed by the sequence of decoders obtained by recursively calling As on the preceding decoder. The unwrapping logic is entirely controlled by the decoder's implementation of the optional As(any) bool method.
func Load ¶ added in v0.2.6
func Load(configPath string, target interface{}) (kratosconfig.Config, error)
Load loads configuration from the specified file path and scans it into the target struct. It returns the Kratos config instance, which should be closed by the caller when no longer needed.
func RegisterSourceFactory ¶ added in v0.2.6
func RegisterSourceFactory(name string, factory SourceFactory)
RegisterSourceFactory registers a source factory for a specific config type.
func RegisterSourceFunc ¶ added in v0.2.6
func RegisterSourceFunc(name string, factory SourceFunc)
RegisterSourceFunc registers a source function for a specific config type.
func WithConfigOption ¶ added in v0.2.6
WithConfigOption appends Kratos config.Option to the Options.
func WithEnvPrefixes ¶ added in v0.2.0
WithEnvPrefixes appends environment variable prefixes to the Options.
func WithKResolveActualTypes ¶ added in v0.2.6
Types ¶
type BuildFunc ¶ added in v0.1.16
type BuildFunc func(*sourcev1.SourceConfig, ...options.Option) (kratosconfig.Source, error)
BuildFunc is a function type that takes a KConfig and a list of Options and returns a Selector and an error.
func (BuildFunc) NewSource ¶ added in v0.2.0
func (fn BuildFunc) NewSource(cfg *sourcev1.SourceConfig, opts ...options.Option) (kratosconfig.Source, error)
NewSource is a method that implements the ConfigBuilder interface for ConfigBuildFunc.
type Builder ¶ added in v0.1.16
type Builder interface {
factory.Registry[SourceFactory]
NewConfig(*sourcev1.Sources, ...options.Option) (interfaces.Config, error)
}
func NewBuilder ¶ added in v0.1.16
func NewBuilder() Builder
NewBuilder creates a new config factory.
type FileConfig ¶ added in v0.2.6
type FileConfig func(*sourcev1.SourceConfig, ...options.Option) (kratosconfig.Source, error)
func (FileConfig) NewSource ¶ added in v0.2.6
func (f FileConfig) NewSource(sourceConfig *sourcev1.SourceConfig, opts ...options.Option) (kratosconfig.Source, error)
type Options ¶ added in v0.1.56
Options holds the configuration for the config module.
func FromOptions ¶ added in v0.2.6
FromOptions retrieves Options pointer from the provided options.Option. It returns nil if the options are not found or opt is nil.
type ProtoSyncer ¶ added in v0.2.0
type SourceFactory ¶ added in v0.2.6
type SourceFactory interface {
// NewSource creates a new config using the given KConfig and a list of Options.
NewSource(*sourcev1.SourceConfig, ...options.Option) (kratosconfig.Source, error)
}
type SourceFunc ¶ added in v0.2.6
type SourceFunc func(*sourcev1.SourceConfig, ...options.Option) (kratosconfig.Source, error)
func (SourceFunc) NewSource ¶ added in v0.2.6
func (c SourceFunc) NewSource(config *sourcev1.SourceConfig, options ...options.Option) (kratosconfig.Source, error)
type SourceType ¶ added in v0.2.6
type SourceType string
const ( SourceTypeFile SourceType = "file" SourceTypeEnv SourceType = "env" )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package envsource is a configuration source that loads environment variables.
|
Package envsource is a configuration source that loads environment variables. |
|
Package file implements the functions, types, and interfaces for the module.
|
Package file implements the functions, types, and interfaces for the module. |
|
internal
|
|
|
reflection
Package reflection implements the functions, types, and interfaces for the module.
|
Package reflection implements the functions, types, and interfaces for the module. |