goconf

package module
v0.0.0-...-17b78c9 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: Unlicense Imports: 6 Imported by: 0

README

goconf

配置文件读取

初始化

conf, err := NewConfig("./config.ini")

获取一个值

value, has := conf.GetValue("conf_02", "B")

获取整型(int)类型值

valueN, has := conf.GetInt("conf_01", "NumberName")

获取字符串类型值

value, has := conf.GetString("conf_01", "StringName")

获取一个布尔类型

ok := conf.GetBool("conf_01", "BoolName")

完整示例


	//加载配置文件
	conf, err := NewConfig("./config.ini")
	if err != nil {
		t.Error(err)
		return
	}

	//获取字符串配置
	value, has := conf.GetString("conf_01", "StringName")
	if has && value == "aaa" {
	} else {
		t.Errorf("获取字符配置项: %s, 获取值: %s", "StringName", value)
	}


	//获取整型数值配置
	valueN, has := conf.GetInt("conf_01", "NumberName")
	if has && valueN == 123  {
	} else {
		t.Errorf("获取整型配置项: %s, 获取值: %d", "NumberName", valueN)
	}


	//获取布尔类型配置
	valueB := conf.GetBool("conf_01", "BoolName")
	if valueB  {
	} else {
		t.Error("获取布尔值配置项失败")
	}


	//获取配置2
	value, has = conf.GetValue("conf_02", "B")
	if has && value == "bbb" {
	} else {
		t.Errorf("配置值: %s, 获取值: %s", "B", value)
	}


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

func NewConfig

func NewConfig(filepath string) (*Config, error)

func (*Config) GetBool

func (c *Config) GetBool(section, name string) bool

获取一个 bool 值配置

func (*Config) GetInt

func (c *Config) GetInt(section, name string) (int, bool)

获取一个 int 配置

func (*Config) GetString

func (c *Config) GetString(section, name string) (string, bool)

获取一个 string 配置

func (*Config) GetValue

func (c *Config) GetValue(section, name string) (string, bool)

获取一个配置项

func (*Config) ReadList

func (c *Config) ReadList() (map[string]map[string]string, error)

读取配置

Jump to

Keyboard shortcuts

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