fconf

package module
v0.0.0-...-83e728b Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: Apache-2.0 Imports: 6 Imported by: 8 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

fconf包读取配置文件数据

这是一个用于引入配置文件的包,加载类似于ini风格的配置文件。 与INI配置文件风格一样 根据顺序读取文件和每一行 如果在行首出现了;号,则认为是配置文件的注释。 除此之外,还提供多种可选类型。

主要支持以下几种类型转换:

String、Int、Int64、Float64

INI演示文件(DEMO)

[mysql]
db1.Name = testMysqlDB
db1.Host = 127.0.0.1
db1.Port = 3306
db1.User = root
db1.Pwd = test

; 测试INI风格的注释
; 这两行数据的前前面加入了分号,因此,这些数据被认为是注释,将不会影响配置文件正常情况

[tcp]
Port=3309

引用示例:

func main() {
	c, err := fconf.NewFileConf("./demo.ini")
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(c.String("mysql.db1.Host"))
	fmt.Println(c.String("mysql.db1.Name"))
	fmt.Println(c.String("mysql.db1.User"))
	fmt.Println(c.String("mysql.db1.Pwd"))

	// 取得配置时指定类型
	port, err := c.Int("mysql.db1.Port")
	if err != nil {
		panic(err)
	}
	fmt.Println(port) // output: 3306(type int)
}

运行以上代码将输出(OUTPUT)

127.0.0.1
testMysqlDB
root
test
3306

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFileReader

func NewFileReader(filePath string) (*os.File, error)

打开一个文件句柄

func PathExists

func PathExists(path string) bool

检查文件或文件夹是否存在

Types

type Config

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

配置文件

func NewFileConf

func NewFileConf(filePath string) (*Config, error)

初始化一个文件配置句柄

func (*Config) Float64

func (c *Config) Float64(tag string) (float64, error)

返回一个float64配置值

func (*Config) Int

func (c *Config) Int(tag string) (int, error)

返回一个Int类型的配置值

func (*Config) Int64

func (c *Config) Int64(tag string) (int64, error)

返回一个int64配置值

func (*Config) String

func (c *Config) String(tag string) string

将指定的配置以字符串返回

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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