config

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

Package config contains generated code by adptool.

Package config provides adapters for Kratos config types and functions.

Index

Constants

View Source
const Module = "config"

Module is the name of the module

Variables

View Source
var (
	ErrInvalidConfigType = runtimeerrors.NewStructured(Module, "invalid config type")
)
View Source
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

func New(srcs *sourcev1.Sources, opts ...options.Option) (interfaces.Config, error)

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 NewKConfig added in v0.2.6

func NewKConfig(opts ...config.Option) config.Config

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

func WithConfigOption(opts ...config.Option) options.Option

WithConfigOption appends Kratos config.Option to the Options.

func WithEnvPrefixes added in v0.2.0

func WithEnvPrefixes(prefixes ...string) options.Option

WithEnvPrefixes appends environment variable prefixes to the Options.

func WithKDecoder added in v0.2.6

func WithKDecoder(d config.Decoder) config.Option

func WithKMergeFunc added in v0.2.6

func WithKMergeFunc(m config.Merge) config.Option

func WithKResolveActualTypes added in v0.2.6

func WithKResolveActualTypes(enableConvertToType bool) config.Option

func WithKResolver added in v0.2.6

func WithKResolver(r config.Resolver) config.Option

func WithKSource added in v0.2.6

func WithKSource(s ...config.Source) config.Option

func WithSource

func WithSource(s ...config.Source) options.Option

WithSource appends config.Source to the Options.

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 KConfig added in v0.1.18

type KConfig = config.Config

type KDecoder added in v0.1.18

type KDecoder = config.Decoder

type KKeyValue added in v0.1.18

type KKeyValue = config.KeyValue

type KMerge added in v0.1.18

type KMerge = config.Merge

type KObserver added in v0.1.18

type KObserver = config.Observer

type KOption added in v0.1.18

type KOption = config.Option

type KReader added in v0.1.18

type KReader = config.Reader

type KResolver added in v0.1.18

type KResolver = config.Resolver

type KSource added in v0.1.18

type KSource = config.Source

type KValue added in v0.1.18

type KValue = config.Value

type KWatcher added in v0.1.18

type KWatcher = config.Watcher

type Options added in v0.1.56

type Options struct {
	ConfigOptions []KOption
	//EnvPrefixes   []string
	Sources []KSource
}

Options holds the configuration for the config module.

func FromOptions added in v0.2.6

func FromOptions(opts ...options.Option) *Options

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.

Jump to

Keyboard shortcuts

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