config

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 5 Imported by: 4

README

config

一个方便使用的Go语言YAML配置读取库,封装自yaml.v3

Go GitHub release (latest by date) GitHub go.mod Go version MIT License Go Report Codacy Badge Codacy Badge

Installation

go get -u github.com/ldigit/config

Quick Start


// Suppose your config file path is config_test.yaml
const ConfigFilePath = "config_test.yaml"

cfg, err := config.Load(ConfigFilePath)
if err != nil {
    log.Fatalln(err)
}

// Suppose there are demo_string entries of type string in your config file
fmt.Println(cfg.GetString("demo_string", "it is default value"))


License

Released under the MIT License.

Documentation

Index

Constants

View Source
const SEPARATOR = "."

SEPARATOR 配置名称中的层级分隔符

Variables

This section is empty.

Functions

func GetGlobalConfig

func GetGlobalConfig() any

GetGlobalConfig 获取全局配置

func LoadAndDecode

func LoadAndDecode(path string, v interface{}) error

LoadAndDecode 加载配置并解析到对象

func SetGlobalConfig

func SetGlobalConfig(cfg any)

SetGlobalConfig 存储到全局配置

Types

type Config

type Config map[string]yaml.Node

func Load

func Load(path string) (*Config, error)

Load 加载配置文件内容

func (Config) Decode

func (c Config) Decode(key string, v any) error

Decode 获取指定KEY的结果值

func (Config) GetBool

func (c Config) GetBool(key string, defaultValue bool) bool

GetBool 获取指定KEY的Bool值

func (Config) GetFloat32

func (c Config) GetFloat32(key string, defaultValue float32) float32

GetFloat32 获取指定KEY的Float32值

func (Config) GetFloat64

func (c Config) GetFloat64(key string, defaultValue float64) float64

GetFloat64 获取指定KEY的Float64值

func (Config) GetInt

func (c Config) GetInt(key string, defaultValue int) int

GetInt 获取指定KEY的Int值

func (Config) GetInt32

func (c Config) GetInt32(key string, defaultValue int32) int32

GetInt32 获取指定KEY的Int32值

func (Config) GetInt64

func (c Config) GetInt64(key string, defaultValue int64) int64

GetInt64 获取指定KEY的Int64值

func (Config) GetString

func (c Config) GetString(key string, defaultValue string) string

GetString 获取指定KEY的字符串值

func (Config) GetUint

func (c Config) GetUint(key string, defaultValue uint) uint

GetUint 获取指定KEY的Uint值

func (Config) GetUint32

func (c Config) GetUint32(key string, defaultValue uint32) uint32

GetUint32 获取指定KEY的Uint32值

func (Config) GetUint64

func (c Config) GetUint64(key string, defaultValue uint64) uint64

GetUint64 获取指定KEY的Uint64值

Jump to

Keyboard shortcuts

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