config

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2022 License: MIT Imports: 8 Imported by: 0

README

config

Go config Package

示例

加载配置文件
import "github.com/tinystack/config"

cfg := config.New()
cfg.SetConfigFile("./config.yaml")

if err := cfg.LoadConfig(); err != nil {
	panic("config load failed")
}
可用的API
cfg.GetFloat64()
cfg.GetBool()
cfg.GetString()
cfg.GetInt()
cfg.GetIntSlice()
cfg.GetStringMap()
cfg.GetStringMapString()
cfg.GetStringSlice()
cfg.GetTime()
cfg.GetDuration()
cfg.Get()

支持的配置文件类型

  • ini
  • yaml/yml
  • toml
  • json
  • env

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDecoder

func RegisterDecoder(fileType FileType, decoder Decoder)

Types

type Config

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

func New

func New() *Config

func (*Config) Get

func (c *Config) Get(key string) interface{}

func (*Config) GetBool

func (c *Config) GetBool(key string) bool

func (*Config) GetDuration

func (c *Config) GetDuration(key string) time.Duration

func (*Config) GetFloat64

func (c *Config) GetFloat64(key string) float64

func (*Config) GetInt

func (c *Config) GetInt(key string) int

func (*Config) GetIntSlice

func (c *Config) GetIntSlice(key string) []int

func (*Config) GetString

func (c *Config) GetString(key string) string

func (*Config) GetStringMap

func (c *Config) GetStringMap(key string) map[string]interface{}

func (*Config) GetStringMapString

func (c *Config) GetStringMapString(key string) map[string]string

func (*Config) GetStringSlice

func (c *Config) GetStringSlice(key string) []string

func (*Config) GetTime

func (c *Config) GetTime(key string) time.Time

func (*Config) LoadConfig

func (c *Config) LoadConfig() error

func (*Config) SetConfigFile

func (c *Config) SetConfigFile(file string)

type Decoder

type Decoder interface {
	Decode([]byte, map[string]interface{}) error
}

type FileType

type FileType uint8
const (
	UnknownFileType FileType = iota
	YamlFileType
	TomlFileType
	IniFileType
	JsonFileType
	EnvFileType
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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