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 New(srcs *sourcev1.Sources, opts ...options.Option) (interfaces.Config, error)
- func NewKConfig(opts ...config.Option) config.Config
- func RegisterSourceFactory(name string, factory SourceFactory)
- 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 Builder
- 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 SourceFactory
- type SourceFunc
- type SourceType
Constants ¶
const Module = "config"
Module is the name of the module
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 New ¶
New is a publicly exposed package-level function for creating config instances. It delegates the call to the default global builder, providing a simple API for common use cases.
func RegisterSourceFactory ¶ added in v0.2.6
func RegisterSourceFactory(name string, factory SourceFactory)
RegisterSourceFactory is a publicly exposed package-level function for registering a SourceFactory. It delegates the call to the default global builder.
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 Builder ¶ added in v0.1.16
type Builder struct {
factory.Registry[SourceFactory]
}
Builder is the builder implementation for configurations. It is exported to allow for creating independent instances for testing or special use cases, while most users will interact with it via the package-level functions that use the default global instance.
func NewBuilder ¶ added in v0.1.16
func NewBuilder() *Builder
NewBuilder creates and returns a new, independent Builder instance. This is useful for testing or for scenarios that require isolated configuration management without affecting the global state.
func (*Builder) NewConfig ¶ added in v0.2.0
func (b *Builder) NewConfig(srcs *sourcev1.Sources, opts ...options.Option) (interfaces.Config, error)
NewConfig creates a new configuration object that conforms to the interfaces.Config interface. It builds a Kratos config from sources, loads it, and immediately wraps it in an adapter to hide the underlying implementation from the rest of the framework.
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 SourceFactory ¶ added in v0.2.6
type SourceFactory interface {
// NewSource creates a new config source.
NewSource(*sourcev1.SourceConfig, ...options.Option) (kratosconfig.Source, error)
}
SourceFactory is the interface for creating configuration sources. It defines a single method, NewSource, which creates a new config source based on the provided configuration and options.
func GetSourceFactory ¶ added in v0.2.13
func GetSourceFactory(name string) (SourceFactory, bool)
GetSourceFactory is a publicly exposed package-level function for retrieving a SourceFactory. It delegates the call to the default global builder.
type SourceFunc ¶ added in v0.2.6
type SourceFunc func(*sourcev1.SourceConfig, ...options.Option) (kratosconfig.Source, error)
SourceFunc is a function type that adapts a function to the SourceFactory interface. This allows registering a simple function as a factory, avoiding the need for a struct.
func (SourceFunc) NewSource ¶ added in v0.2.6
func (c SourceFunc) NewSource(config *sourcev1.SourceConfig, options ...options.Option) (kratosconfig.Source, error)
NewSource makes SourceFunc implement the SourceFactory interface. The function itself becomes the factory method.
type SourceType ¶ added in v0.2.6
type SourceType string
const ( SourceTypeFile SourceType = "file" SourceTypeEnv SourceType = "env" )
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. |
|
Package protoutil provides utility functions for working with protobuf Any messages.
|
Package protoutil provides utility functions for working with protobuf Any messages. |