// config.ini
[app]
server.port = 8080
name = resk
enabled = false
time = 10s
;我是一个注释
#mysql数据库配置
[mysql]
driverName = mysql
address = 192.168.232.175:3306
username = po
password = 111111
database = po
// main.go
package main
import (
"fmt"
"github.com/tietang/props/ini"
"github.com/tietang/props/kvs"
"time"
)
func main() {
file := kvs.GetCurrentFilePath("config.ini", 1)
conf := ini.NewIniFileConfigSource(file)
port := conf.GetIntDefault("app.server.port", 18080)
fmt.Println(port)
fmt.Println(conf.GetDefault("app.name", "unknow"))
fmt.Println(conf.GetBoolDefault("app.enabled", false))
fmt.Println(conf.GetDurationDefault("app.time", time.Second))
}
|
请发表评论