config

package
v0.0.36 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

func InitConfig

func InitConfig() error

func InitYamlConfig

func InitYamlConfig(out interface{}) error

func MapTo

func MapTo(section string, v interface{})

func RegisterConfig

func RegisterConfig(name string, setting interface{}, desc string)

func RegisterConfigChangeCallback

func RegisterConfigChangeCallback(f func())

func UnmarshalFromNode

func UnmarshalFromNode(node any, out interface{}) error

Types

type ConfigSetting

type ConfigSetting struct {
	Name        string
	Description string
	Setting     interface{}
}

Module Config Settings

type DurationDecoder

type DurationDecoder struct{}

func (*DurationDecoder) Decode

func (*DurationDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator)

type IYmlConfig

type IYmlConfig interface {
	ConfigFileChangeListen()
	Clone(fileName string) IYmlConfig
	Get(keyName string) interface{}
	GetString(keyName string) string
	GetBool(keyName string) bool
	GetInt(keyName string) int
	GetInt32(keyName string) int32
	GetInt64(keyName string) int64
	GetFloat64(keyName string) float64
	GetDuration(keyName string) time.Duration
	GetStringSlice(keyName string) []string
}

由于 vipver 包本身对于文件的变化事件有一个bug,相关事件会被回调两次 常年未彻底解决,相关的 issue 清单:https://github.com/spf13/viper/issues?q=OnConfigChange 设置一个内部全局变量,记录配置文件变化时的时间点,如果两次回调事件事件差小于1秒,我们认为是第二次回调事件,而不是人工修改配置文件 这样就避免了 viper 包的这个bug

var ConfigYml IYmlConfig

func CreateYamlFactory

func CreateYamlFactory(fileName ...string) IYmlConfig

CreateYamlFactory 创建一个yaml配置文件工厂 参数设置为可变参数的文件名,这样参数就可以不需要传递,如果传递了多个,我们只取第一个参数作为配置文件名

type JsonExtension

type JsonExtension struct {
	jsoniter.DummyExtension
}

func (*JsonExtension) CreateDecoder

func (*JsonExtension) CreateDecoder(typ reflect2.Type) jsoniter.ValDecoder

Jump to

Keyboard shortcuts

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