zoukankan      html  css  js  c++  java
  • go config

    安装导入

    go get github.com/astaxie/beego/config
    import "github.com/astaxie/beego/config"
    

    使用

    配置文件内容

    [server]
    ip=0.0.0.0
    port=8088
    
    [logs]
    log_level=debug
    log_path=./logs/logagent.log_level
    
    [collect]
    log_path=/home/work/logs/nginx/access.log
    topic=nginx_log
    

    代码

    package main
    
    import (
    	"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)
    }
    
  • 相关阅读:
    示例 json with js
    JS json
    jquery
    发布包规范
    20180320待编辑
    CefSharp中c#和js交互
    列举mvc ActionResult的返回值
    怎么实现第三方登录
    mvc @Html控件
    MVC webuploader 图片
  • 原文地址:https://www.cnblogs.com/shhnwangjian/p/7527281.html
Copyright © 2011-2022 走看看