Coder Social home page Coder Social logo

fconf's Introduction

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("~")
	}
	fmt.Println(port)
}

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

127.0.0.1
testMysqlDB
root
test
3306

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.