Documentation
¶
Overview ¶
Package config contains generated code by adptool.
Package config provides adapters for Kratos config types and functions.
Index ¶
- Constants
- Variables
- func Load(configPath string, target interface{}) (kratosconfig.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 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 is a publicly exposed package-level function for registering a SourceFactory.
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 {
builder.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.
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.
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 contracts for the module.
|
Package file implements the functions, types, and contracts for the module. |
|
internal
|
|
|
reflection
Package reflection implements the functions, types, and contracts for the module.
|
Package reflection implements the functions, types, and contracts 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. |