config

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 13 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"

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

func NewConfig(cfg *sourcev1.Sources, opts ...options.Option) (interfaces.Config, error)

NewConfig creates a new config instance.

func NewKConfig added in v0.2.6

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

func Register added in v0.2.6

func Register(name string, sourceFactory any)

Register registers a config factory.

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

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 BuildFunc added in v0.1.16

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 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 ProtoSyncer added in v0.2.0

type ProtoSyncer interface {
	SyncConfig(*sourcev1.SourceConfig, string, proto.Message, ...options.Option) error
}

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"
)

type Syncer added in v0.1.16

type Syncer interface {
	SyncConfig(*sourcev1.SourceConfig, string, proto.Message, ...options.Option) error
}

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.

Jump to

Keyboard shortcuts

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