config

package
v0.2.10-14 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CfgDir   string
	CfgPath  string
	Replacer = strings.NewReplacer(".", "_", "-", "_", "/", "_")
)

Functions

func Load

func Load[T any]() T

Types

type CfgMap

type CfgMap map[string]any

func (CfgMap) Decode

func (c CfgMap) Decode(val any, tags ...string) error

type Config

type Config interface {
	UnmarshalKey(key string, rawVal interface{}, opts ...DecoderOption) error
	Unmarshal(rawVal interface{}, opts ...DecoderOption) error

	// DecodeComponent decode component config to map[string]*struct
	DecodeComponent(name string, cfgMap interface{}) error
	Get(key string) interface{}
	Set(string, interface{})
	GetString(key string) string
	AllKeys() []string
	All() map[string]interface{}
}

func New

func New() Config

New 处理所有的配置,环境变量和flag 配置顺序, 默认值->环境变量->配置文件->flag 配置文件中可以设置环境变量 flag可以指定配置文件位置 始化配置文件

type DecoderOption

type DecoderOption = viper.DecoderConfigOption

Jump to

Keyboard shortcuts

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