安装导入
go get github.com/astaxie/beego/configimport "github.com/astaxie/beego/config"
使用
配置文件内容
[server]ip=0.0.0.0port=8088[logs]log_level=debuglog_path=./logs/logagent.log_level[collect]log_path=/home/work/logs/nginx/access.logtopic=nginx_log
代码
package mainimport ( "fmt" "github.com/astaxie/beego/config")func main() { conf, err := config.NewConfig("ini", "./logagent.conf") if err != nil { fmt.Println("new config failed, err:", err) return } port, err := conf.Int("server::port") if err != nil { fmt.Println("read server:port failed, err:", err) return } fmt.Println("Port:", port) log_level := conf.String("logs::log_level") if len(log_level) == 0 { log_level = "debug" } fmt.Println("log_level:", log_level) log_path := conf.String("logs::log_path") fmt.Println("log_path:", log_path)}