config

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 24 Imported by: 0

README

Config

kubernetes

go get -u github.com/go-kratos/kratos/contrib/config/kubernetes/v2

apollo

go get -u github.com/go-kratos/kratos/contrib/config/apollo/v2

etcd

go get -u github.com/go-kratos/kratos/contrib/config/etcd/v2

nacos

go get -u github.com/go-kratos/kratos/contrib/config/nacos/v2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is key not found.
	ErrNotFound = errors.New("key not found")
	// ErrTypeAssert is type assert error.
	ErrTypeAssert = errors.New("type assert error")
)

Functions

func Close

func Close() error

func Init

func Init(sources ...sources.Source)

Init config source, inconvenient for user, because of circular reference

func InitSources

func InitSources(paths ...string)

InitSources init config source, with env

func Load

func Load()

func Scan

func Scan[T any](keys ...string) T

Scan any type

func Watch

func Watch(key string, o Observer) error

Types

type Config

type Config interface {
	Load() error
	Scan(v interface{}) error
	Value(key string) Value
	Watch(key string, o Observer) error
	Close() error
}

Config is a config interface.

func New

func New(opts ...Option) Config

New ,new a config with options.

type Decoder

type Decoder func(*sources.KeyValue, map[string]interface{}) error

Decoder is config decoder.

type Manager

type Manager struct {
	Config
}

Manager config manager, hold the config

type Observer

type Observer func(string, Value)

Observer is config observer.

type Option

type Option func(*options)

Option is config option.

func WithDecoder

func WithDecoder(d Decoder) Option

WithDecoder with config decoder. DefaultDecoder behavior: If KeyValue.Format is non-empty, then KeyValue.Value will be deserialized into map[string]interface{} and stored in the config cache(map[string]interface{}) if KeyValue.Format is empty,{KeyValue.Key : KeyValue.Value} will be stored in config cache(map[string]interface{})

func WithResolver

func WithResolver(r Resolver) Option

WithResolver with config resolver.

func WithSource

func WithSource(s ...sources.Source) Option

WithSource with config source.

type Reader

type Reader interface {
	Merge(...*sources.KeyValue) error
	Value(string) (Value, bool)
	Source() ([]byte, error)
	Resolve() error
}

Reader is config reader.

type Resolver

type Resolver func(map[string]interface{}) error

Resolver resolve placeholder in config.

type Value

type Value interface {
	Bool() (bool, error)
	Int() (int64, error)
	Float() (float64, error)
	String() (string, error)
	Duration() (time.Duration, error)
	Slice() ([]Value, error)
	Map() (map[string]Value, error)
	Scan(interface{}) error
	Load() interface{}
	Store(interface{})
}

Value is config value interface.

func GetValue

func GetValue(key string) Value

Directories

Path Synopsis
env

Jump to

Keyboard shortcuts

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