config

package
v0.0.0-...-4dc1fac Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeDefFile

func MakeDefFile(cfg interface{}, defFile string) error

通过结构体,生成默认文件

Types

type Config

type Config interface {

	// Init the config
	Init(opts ...Option) error
	// Options in the config
	Options() Options
	// Stop the config loader/watcher
	Close() error
	// Load config sources
	Load(opts ...Option) error
	// Force a source changeset sync
	Sync() error

	Get(key string) (string, bool)              //获取参数, 后续可返回values
	Walk(f func(key string, value string) bool) //遍历参数,并执行操作处理函数

}

type Option

type Option func(*Options)

func WithConfigFile

func WithConfigFile(path string, dataType string) Option

func WithConfigName

func WithConfigName(cfgName string) Option

func WithConfigPath

func WithConfigPath(path string) Option

func WithConfigType

func WithConfigType(cfgType string) Option

func WithDefConfigData

func WithDefConfigData(data []byte, dataType string) Option

func WithEnvPrefix

func WithEnvPrefix(prefix string) Option

只在初始化时有效

type Options

type Options struct {
	Context context.Context
	// contains filtered or unexported fields
}

读取配置的参数

type VConfig

type VConfig struct {
	// contains filtered or unexported fields
}

func NewVConfig

func NewVConfig(opts ...Option) (*VConfig, error)

func (*VConfig) ReadConfigFile

func (vc *VConfig) ReadConfigFile(opts ...Option) error

func (*VConfig) Unmarshal

func (vc *VConfig) Unmarshal(cfg interface{}) error

func (*VConfig) UnmarshalKey

func (vc *VConfig) UnmarshalKey(key string, cfg interface{}) error

func (*VConfig) WriteConfigAs

func (vc *VConfig) WriteConfigAs(file string) error

Jump to

Keyboard shortcuts

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